Repository navigation
Description
We were running some middleware scenario where our ASP.NET site would make outgoing request via HttpClient. The request would be cancelled at any time. In the stress run I saw many first chance C++ exception and then accompanying CLR System.ObjectDisposedException on SafeHandle. Actually the WinHttpRequestState already shows it’s disposed. Although the exception would be populated and handled, it sounds more perf/debug-friendly to avoid it by checking the state object before making the PInvoke calls to native code and throw exception.
0:019> !mk
Thread 19:
SP IP
00:U 000000ac8b21e590 00007ffcc8398a5c KERNELBASE!RaiseException+0x68 [d:\blue\minkernel\kernelbase\xcpt.c @ 828]
01:U 000000ac8b21e670 00007ffca297670c coreclr!RaiseTheExceptionInternalOnly+0x3a4 [f:\dd\ndp\clr\src\vm\excep.cpp @ 3113]
02:U 000000ac8b21e7a0 00007ffca297a8f6 coreclr!UnwindAndContinueRethrowHelperAfterCatch+0x76 [f:\dd\ndp\clr\src\vm\excep.cpp @ 8747]
03:U 000000ac8b21e7f0 00007ffca2a196a2 coreclr!SafeHandle::DangerousAddRef+0xce [f:\dd\ndp\clr\src\vm\safehandle.cpp @ 415]
04:M 000000ac8b21e970 00007ffca2500ad0 System.StubHelpers.StubHelpers.SafeHandleAddRef(System.Runtime.InteropServices.SafeHandle, Boolean ByRef)(+0x1a IL,+0x20 Native) [f:\dd\ndp\clr\src\mscorlib\src\System\StubHelpers.cs @ 1679,13]
05:M 000000ac8b21e9b0 00007ffc44a1a6bd DomainBoundILStubClass.IL_STUB_PInvoke(SafeWinHttpHandle, IntPtr)
06:U 000000ac8b21e9b8 000000ab6417dff0 CLRStub@000000ab6417dff0
07:M 000000ac8b21e9c0 00007ffca2499efe System.Threading.TimerQueueTimer.Close()(+0x6e Native) [f:\dd\ndp\clr\src\mscorlib\src\System\Threading\Timer.cs @ 599,9]
08:M 000000ac8b21ea80 00007ffc44a1a5d2 System.Net.Http.WinHttpHandler.InternalReceiveResponseHeadersAsync(System.Net.Http.WinHttpRequestState)(+0xe2 Native) [f:\dd\ndp\fxcore\Open\src\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpHandler.cs @ 1361,13]
09:M 000000ac8b21eae0 00007ffc44a07ca0 System.Net.Http.WinHttpHandler+d__102.MoveNext()(+0x40a IL,+0x7d0 Native) [f:\dd\ndp\fxcore\Open\src\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpHandler.cs @ 849,25]
0a:M 000000ac8b21ebf0 00007ffca2431903 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)(+0x15 IL,+0x83 Native) [f:\dd\ndp\clr\src\mscorlib\src\System\Threading\ExecutionContext.cs @ 93,17]
0b:M 000000ac8b21ec60 00007ffca249a5c1 System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()(+0x24 IL,+0x91 Native) [f:\dd\ndp\clr\src\mscorlib\src\System\Runtime\CompilerServices\AsyncMethodBuilder.cs @ 1071,25]
0c:M 000000ac8b21ecb0 00007ffca2497627 System.Threading.ThreadPoolWorkQueue.Dispatch()(+0xa4 IL,+0x1c7 Native) [f:\dd\ndp\clr\src\mscorlib\src\System\Threading\ThreadPool.cs @ 815,29]
0d:U 000000ac8b21ed50 00007ffca2cf2503 coreclr!CallDescrWorkerInternal+0x83 [f:\dd\ndp\clr\src\vm\amd64\CallDescrWorkerAMD64.asm @ 101]
0e:U 000000ac8b21ed90 00007ffca299b907 coreclr!MethodDescCallSite::CallTargetWorker+0x20f [f:\dd\ndp\clr\src\vm\callhelpers.cpp @ 653]
0f:U 000000ac8b21eea0 00007ffca2aebc96 coreclr!QueueUserWorkItemManagedCallback+0x2a [f:\dd\ndp\clr\src\vm\comthreadpool.cpp @ 510]
10:U 000000ac8b21ef90 00007ffca2957921 coreclr!ManagedThreadBase_DispatchMiddle+0x89 [f:\dd\ndp\clr\src\vm\threads.cpp @ 10144]
11:U 000000ac8b21f0f0 00007ffca2957c6c coreclr!ManagedThreadBase_DispatchOuter+0xb4 [f:\dd\ndp\clr\src\vm\threads.cpp @ 10399]
12:U 000000ac8b21f1a0 00007ffca2957d06 coreclr!ManagedThreadBase::ThreadPool+0x32 [f:\dd\ndp\clr\src\vm\threads.cpp @ 10505]
13:U 000000ac8b21f200 00007ffca2a7be50 coreclr!ManagedPerAppDomainTPCount::DispatchWorkItem+0xe4 [f:\dd\ndp\clr\src\vm\threadpoolrequest.cpp @ 760]
14:U 000000ac8b21f350 00007ffca2a7523a coreclr!ThreadpoolMgr::ExecuteWorkRequest+0x13a [f:\dd\ndp\clr\src\vm\win32threadpool.cpp @ 1891]
15:U 000000ac8b21f3a0 00007ffca2a75d25 coreclr!ThreadpoolMgr::WorkerThreadStart+0x4cd [f:\dd\ndp\clr\src\vm\win32threadpool.cpp @ 2361]
16:U 000000ac8b21f440 00007ffca295243c coreclr!Thread::intermediateThreadProc+0x80 [f:\dd\ndp\clr\src\vm\threads.cpp @ 2859]
17:U 000000ac8b21fe80 00007ffcca3413d2 kernel32!BaseThreadInitThunk+0x22 [d:\9147\base\win32\client\thread.c @ 78]
18:U 000000ac8b21feb0 00007ffccafa54e4 ntdll!RtlUserThreadStart+0x34 [d:\blue\minkernel\ntdll\rtlstrt.c @ 1026]
0:019> !mdt 000000ab630f2738
000000ab630f2738 (System.Net.Http.WinHttpRequestState)
_lock:000000ab630f2810 (System.Object)
_operationHandle:(System.Runtime.InteropServices.GCHandle) VALTYPE (MT=00007ffca2748ef0, ADDR=000000ab630f27e0)
_disposed:true (System.Boolean)
k__BackingField:000000ab630f26d0 (System.Threading.Tasks.TaskCompletionSource`1[[System.Net.Http.HttpResponseMessage, System.Net.Http]])
k__BackingField:(System.Threading.CancellationToken) VALTYPE (MT=00007ffca2754758, ADDR=000000ab630f27e8)
k__BackingField:000000ab630f22d0 (System.Net.Http.HttpRequestMessage)
k__BackingField:000000ab630f19e0 (System.Net.Http.WinHttpHandler)
k__BackingField:000000ab6417d920 (Interop+WinHttp+SafeWinHttpHandle)
k__BackingField:NULL (System.Exception)
k__BackingField:false (System.Boolean)
…
000000ac8b21f120 0:019> !mdt 000000ab6417d920
000000ab6417d920 (Interop+WinHttp+SafeWinHttpHandle)
handle:000000ac8a3f7200 (System.IntPtr)
_state:0x3 (System.Int32)
_ownsHandle:true (System.Boolean)
_fullyInitialized:true (System.Boolean)
_parentHandle:NULL (Interop+WinHttp+SafeWinHttpHandle)
Activity
yuwaMSFT commentedon Apr 22, 2016
@CIPop @davidsh @stephentoub @sivarv @sajayantony @halter73 @muratg
[-]Lots of first chance exception System.ObjectDisposedException on SafeHandler in middleware scenario when request is cancelled[/-][+]Lots of first chance exception System.ObjectDisposedException on SafeHandle in middleware scenario when request is cancelled[/+]davidsh commentedon Jun 17, 2016
Closing this since this is a dupe of the root issue in dotnet/corefx#9228.