This needs more investigation on whether we're trying to dispose HttpClient while still using it or if there is a other race condition inside HttpClient cleanup itself.
The following scenario (pseudo-code) produces numerous native memory leaks. Note that the memory only leaks if there is a race condition (e.g. the channel factory or the channel are being used while the channel factory is being closed).
This is a valid scenario for WCF. The workaround is to avoid doing this scenario.
Here are the top call stacks:
+ 436423360 ( 458918560 - 22495200) 27847 allocs BackTrace3CB2363D
+ 26482 ( 27847 - 1365) BackTrace3CB2363D allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
webio!WaCreateEndpointManager+30 (d:\9147\net\webio\core\epmgr.c, 204)
webio!WapCreateSession+8E (d:\9147\net\webio\core\session.c, 258)
webio!WapCreateSessionHandle+9F (d:\9147\net\webio\core\session.c, 558)
webio!WebCreateSession+E (d:\9147\net\webio\core\session.c, 1258)
winhttp!WinHttpSendRequest+6A4 (d:\9147\net\winhttp\api\sendapi.cxx, 218)
<no module>!???+0 : 7FFCDE65B579
+ 108893984 ( 114506864 - 5612880) 27847 allocs BackTrace3CB237BD
+ 26482 ( 27847 - 1365) BackTrace3CB237BD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
webio!WaCreateCookieJar+3D (d:\9147\net\webio\cookies\cookiejar.c, 5447)
webio!WapCreateSession+AC (d:\9147\net\webio\core\session.c, 281)
webio!WapCreateSessionHandle+9F (d:\9147\net\webio\core\session.c, 558)
webio!WebCreateSession+E (d:\9147\net\webio\core\session.c, 1258)
winhttp!WinHttpSendRequest+6A4 (d:\9147\net\winhttp\api\sendapi.cxx, 218)
<no module>!???+0 : 7FFCDE65B579
+ 83259408 ( 87550968 - 4291560) 27847 allocs BackTrace3CB2387D
+ 26482 ( 27847 - 1365) BackTrace3CB2387D allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
webio!WaCreateDnsCache+3C (d:\9147\net\webio\util\dnsquery.c, 1393)
webio!WapCreateSession+BE (d:\9147\net\webio\core\session.c, 288)
webio!WapCreateSessionHandle+9F (d:\9147\net\webio\core\session.c, 558)
webio!WebCreateSession+E (d:\9147\net\webio\core\session.c, 1258)
winhttp!WinHttpSendRequest+6A4 (d:\9147\net\winhttp\api\sendapi.cxx, 218)
<no module>!???+0 : 7FFCDE65B579
+ 12711360 ( 13366560 - 655200) 27847 allocs BackTrace3C8F69BD
+ 26482 ( 27847 - 1365) BackTrace3C8F69BD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
winhttp!WinHttpOpen+1DF (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 8474240 ( 8911040 - 436800) 27847 allocs BackTrace3CB239FD
+ 26482 ( 27847 - 1365) BackTrace3CB239FD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
ntdll!TpAllocTimer+88 (d:\9141\minkernel\threadpool\ntdll\timer.c, 1550)
KERNELBASE!CreateThreadpoolTimer+18 (d:\9147\minkernel\threadpool\kernel32\threadpool.c, 165)
webio!WaCreateTimer+5F (d:\9147\net\webio\util\timer.c, 258)
webio!WaCreateDnsCache+A0 (d:\9147\net\webio\util\dnsquery.c, 1425)
webio!WapCreateSession+BE (d:\9147\net\webio\core\session.c, 288)
webio!WapCreateSessionHandle+9F (d:\9147\net\webio\core\session.c, 558)
webio!WebCreateSession+E (d:\9147\net\webio\core\session.c, 1258)
winhttp!WinHttpSendRequest+6A4 (d:\9147\net\winhttp\api\sendapi.cxx, 218)
<no module>!???+0 : 7FFCDE65B579
+ 8474240 ( 8911040 - 436800) 27847 allocs BackTrace3CB236FD
+ 26482 ( 27847 - 1365) BackTrace3CB236FD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
ntdll!TpAllocTimer+88 (d:\9141\minkernel\threadpool\ntdll\timer.c, 1550)
KERNELBASE!CreateThreadpoolTimer+18 (d:\9147\minkernel\threadpool\kernel32\threadpool.c, 165)
webio!WaCreateSettableTimer+3E (d:\9147\net\webio\util\timer.c, 333)
webio!WaCreateEndpointManager+C9 (d:\9147\net\webio\core\epmgr.c, 248)
webio!WapCreateSession+8E (d:\9147\net\webio\core\session.c, 258)
webio!WapCreateSessionHandle+9F (d:\9147\net\webio\core\session.c, 558)
webio!WebCreateSession+E (d:\9147\net\webio\core\session.c, 1258)
winhttp!WinHttpSendRequest+6A4 (d:\9147\net\winhttp\api\sendapi.cxx, 218)
<no module>!???+0 : 7FFCDE65B579
+ 8474240 ( 8911040 - 436800) 27847 allocs BackTrace3C90C0FD
+ 26482 ( 27847 - 1365) BackTrace3C90C0FD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
ntdll!TpAllocTimer+88 (d:\9141\minkernel\threadpool\ntdll\timer.c, 1550)
KERNELBASE!CreateThreadpoolTimer+18 (d:\9147\minkernel\threadpool\kernel32\threadpool.c, 165)
winhttp!WxCreateThreadpoolTimer+5B (d:\9147\inetcore\inetcommon\wxlib\wx_threadpool.cpp, 148)
winhttp!WinHttpClientSession::FinalConstruct+24 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 2689)
winhttp!WinHttpClientSession::CreateInstance+74 (d:\9147\inetcore\inetcommon\proxylib\inc\wxp_winhttpclient.h, 34)
winhttp!WinHttpClientResolver::Initialize+95 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 1392)
winhttp!WinHttpClientResolver::CreateInstance+89 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 2639)
winhttp!CreateWinHttpClientResolverInstance+4B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 891)
winhttp!CreateAutoProxyForWinHttp+67 (d:\9147\net\winhttp\proxy\proxyhelper.cpp, 199)
winhttp!WxProxyManager::Initialize+456F7 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 829)
winhttp!WxProxyManager::CreateInstance+67 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 1966)
winhttp!CreateProxyManagerResolverInstance+3B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 915)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::LoadAutomaticProxyResolvers+202 (d:\9147\net\winhttp\handles\hinet.cxx, 2007)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::SetProxySettings+44ED5 (d:\9147\net\winhttp\handles\hinet.cxx, 2167)
winhttp!WinHttpSetOptionInternal+397 (d:\9147\net\winhttp\api\options.cxx, 1967)
winhttp!WinHttpOpen+27A (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 8474240 ( 8911040 - 436800) 27847 allocs BackTrace3C90B53D
+ 26482 ( 27847 - 1365) BackTrace3C90B53D allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
winhttp!WinHttpClientResolver::CreateInstance+59 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 2636)
winhttp!CreateWinHttpClientResolverInstance+4B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 891)
winhttp!CreateAutoProxyForWinHttp+67 (d:\9147\net\winhttp\proxy\proxyhelper.cpp, 199)
winhttp!WxProxyManager::Initialize+456F7 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 829)
winhttp!WxProxyManager::CreateInstance+67 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 1966)
winhttp!CreateProxyManagerResolverInstance+3B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 915)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::LoadAutomaticProxyResolvers+202 (d:\9147\net\winhttp\handles\hinet.cxx, 2007)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::SetProxySettings+44ED5 (d:\9147\net\winhttp\handles\hinet.cxx, 2167)
winhttp!WinHttpSetOptionInternal+397 (d:\9147\net\winhttp\api\options.cxx, 1967)
winhttp!WinHttpOpen+27A (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 5720112 ( 6014952 - 294840) 27847 allocs BackTrace3C90C23D
+ 26482 ( 27847 - 1365) BackTrace3C90C23D allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
ntdll!TpAllocWork+92 (d:\9141\minkernel\threadpool\ntdll\work.c, 330)
KERNELBASE!CreateThreadpoolWork+18 (d:\9147\minkernel\threadpool\kernel32\threadpool.c, 149)
winhttp!WxCreateThreadpoolWork+5B (d:\9147\inetcore\inetcommon\wxlib\wx_threadpool.cpp, 63)
winhttp!WinHttpClientSession::FinalConstruct+45 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 2694)
winhttp!WinHttpClientSession::CreateInstance+74 (d:\9147\inetcore\inetcommon\proxylib\inc\wxp_winhttpclient.h, 34)
winhttp!WinHttpClientResolver::Initialize+95 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 1392)
winhttp!WinHttpClientResolver::CreateInstance+89 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 2639)
winhttp!CreateWinHttpClientResolverInstance+4B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 891)
winhttp!CreateAutoProxyForWinHttp+67 (d:\9147\net\winhttp\proxy\proxyhelper.cpp, 199)
winhttp!WxProxyManager::Initialize+456F7 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 829)
winhttp!WxProxyManager::CreateInstance+67 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 1966)
winhttp!CreateProxyManagerResolverInstance+3B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 915)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::LoadAutomaticProxyResolvers+202 (d:\9147\net\winhttp\handles\hinet.cxx, 2007)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::SetProxySettings+44ED5 (d:\9147\net\winhttp\handles\hinet.cxx, 2167)
winhttp!WinHttpSetOptionInternal+397 (d:\9147\net\winhttp\api\options.cxx, 1967)
winhttp!WinHttpOpen+27A (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 4237120 ( 4455520 - 218400) 27847 allocs BackTrace3C90A5BD
+ 26482 ( 27847 - 1365) BackTrace3C90A5BD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
winhttp!WxProxyManager::CreateInstance+3D (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 1963)
winhttp!CreateProxyManagerResolverInstance+3B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 915)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::LoadAutomaticProxyResolvers+202 (d:\9147\net\winhttp\handles\hinet.cxx, 2007)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::SetProxySettings+44ED5 (d:\9147\net\winhttp\handles\hinet.cxx, 2167)
winhttp!WinHttpSetOptionInternal+397 (d:\9147\net\winhttp\api\options.cxx, 1967)
winhttp!WinHttpOpen+27A (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 2754128 ( 2896088 - 141960) 27847 allocs BackTrace3C90B9FD
+ 26482 ( 27847 - 1365) BackTrace3C90B9FD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
combase!CoTaskMemAlloc+3A (d:\9147\com\combase\class\memapi.cxx, 459)
winhttp!HostProxyMap::CreateInstance+66 (d:\9147\inetcore\inetcommon\proxylib\inc\wxp_hostproxymap.h, 64)
winhttp!AutoProxyBase::Initialize+33 (d:\9147\inetcore\inetcommon\proxylib\autoprox.cpp, 204)
winhttp!WinHttpClientResolver::Initialize+37 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 1382)
winhttp!WinHttpClientResolver::CreateInstance+89 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 2639)
winhttp!CreateWinHttpClientResolverInstance+4B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 891)
winhttp!CreateAutoProxyForWinHttp+67 (d:\9147\net\winhttp\proxy\proxyhelper.cpp, 199)
winhttp!WxProxyManager::Initialize+456F7 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 829)
winhttp!WxProxyManager::CreateInstance+67 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 1966)
winhttp!CreateProxyManagerResolverInstance+3B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 915)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::LoadAutomaticProxyResolvers+202 (d:\9147\net\winhttp\handles\hinet.cxx, 2007)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::SetProxySettings+44ED5 (d:\9147\net\winhttp\handles\hinet.cxx, 2167)
winhttp!WinHttpSetOptionInternal+397 (d:\9147\net\winhttp\api\options.cxx, 1967)
winhttp!WinHttpOpen+27A (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 2754128 ( 2896088 - 141960) 27847 allocs BackTrace3C90A1BD
+ 26482 ( 27847 - 1365) BackTrace3C90A1BD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
combase!CoTaskMemAlloc+3A (d:\9147\com\combase\class\memapi.cxx, 459)
winhttp!WxProxyList::Initialize+70 (d:\9147\inetcore\inetcommon\proxylib\badproxy.cpp, 102)
winhttp!WxProxyList::CreateInstance+7F (d:\9147\inetcore\inetcommon\proxylib\badproxy.cpp, 76)
winhttp!CreateBadProxyListInstance+32 (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 813)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::LoadAutomaticProxyResolvers+1D3 (d:\9147\net\winhttp\handles\hinet.cxx, 2005)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::SetProxySettings+44ED5 (d:\9147\net\winhttp\handles\hinet.cxx, 2167)
winhttp!WinHttpSetOptionInternal+397 (d:\9147\net\winhttp\api\options.cxx, 1967)
winhttp!WinHttpOpen+27A (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 2754128 ( 2896088 - 141960) 27847 allocs BackTrace3C8F6BFD
+ 26482 ( 27847 - 1365) BackTrace3C8F6BFD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
combase!CoTaskMemAlloc+3A (d:\9147\com\combase\class\memapi.cxx, 459)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::INTERNET_SESSION_HANDLE_OBJECT+394 (d:\9147\net\winhttp\handles\hinet.cxx, 1087)
winhttp!WinHttpOpen+1F3 (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8
+ 2542272 ( 2673312 - 131040) 27847 allocs BackTrace3CB2357D
+ 26482 ( 27847 - 1365) BackTrace3CB2357D allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
webio!WapCreateSession+3A (d:\9147\net\webio\core\session.c, 227)
webio!WapCreateSessionHandle+9F (d:\9147\net\webio\core\session.c, 558)
webio!WebCreateSession+E (d:\9147\net\webio\core\session.c, 1258)
winhttp!WinHttpSendRequest+6A4 (d:\9147\net\winhttp\api\sendapi.cxx, 218)
<no module>!???+0 : 7FFCDE65B579
+ 2330416 ( 2450536 - 120120) 27847 allocs BackTrace3C90BBFD
+ 26482 ( 27847 - 1365) BackTrace3C90BBFD allocations
ntdll!RtlpCallInterceptRoutine+40 (d:\9141\minkernel\ntos\rtl\heappriv.h, 3625)
ntdll!RtlAllocateHeap+7B5F8 (d:\9141\minkernel\ntos\rtl\heap.c, 1892)
winhttp!WinHttpClientSession::CreateInstance+25 (d:\9147\inetcore\inetcommon\proxylib\inc\wxp_winhttpclient.h, 34)
winhttp!WinHttpClientResolver::Initialize+95 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 1392)
winhttp!WinHttpClientResolver::CreateInstance+89 (d:\9147\inetcore\inetcommon\proxylib\winhttpclient.cpp, 2639)
winhttp!CreateWinHttpClientResolverInstance+4B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 891)
winhttp!CreateAutoProxyForWinHttp+67 (d:\9147\net\winhttp\proxy\proxyhelper.cpp, 199)
winhttp!WxProxyManager::Initialize+456F7 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 829)
winhttp!WxProxyManager::CreateInstance+67 (d:\9147\inetcore\inetcommon\proxylib\proxymanager.cpp, 1966)
winhttp!CreateProxyManagerResolverInstance+3B (d:\9147\inetcore\inetcommon\proxylib\proxyutil.cpp, 915)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::LoadAutomaticProxyResolvers+202 (d:\9147\net\winhttp\handles\hinet.cxx, 2007)
winhttp!INTERNET_SESSION_HANDLE_OBJECT::SetProxySettings+44ED5 (d:\9147\net\winhttp\handles\hinet.cxx, 2167)
winhttp!WinHttpSetOptionInternal+397 (d:\9147\net\winhttp\api\options.cxx, 1967)
winhttp!WinHttpOpen+27A (d:\9147\net\winhttp\api\inetapiw.cxx, 1344)
<no module>!???+0 : 7FFCDE6525E8