Skip to content

Deadlock with SystemEvents when application is shutdown by Restart Manager #62042

Closed

Description

@filipnavara

Description

There's an unhandled condition in SystemEvents class when the window message processing thread is shutdown by the WM_QUIT message. The code assumes the message is sent by the Shutdown method but it can be received from external actor, such as the Restart Manager component in Windows.

This results in the following shutdown deadlock:

Thread 1:

...
0517F044 7090ac81 coreclr!CLREventBase::Wait + 0x1a [D:\a\_work\1\s\src\coreclr\vm\synch.cpp:413], calling coreclr!CLREventBase::WaitEx [D:\a\_work\1\s\src\coreclr\vm\synch.cpp:417]
0517F054 770bef00 KERNELBASE!SetEvent + 0x10, calling ntdll_77e10000!NtSetEvent
0517F05C 7094ffd0 coreclr!FinalizerThread::RaiseShutdownEvents + 0x45 [D:\a\_work\1\s\src\coreclr\vm\finalizerthread.h:64], calling coreclr!CLREventBase::Wait [D:\a\_work\1\s\src\coreclr\vm\synch.cpp:410]
0517F06C 708ebee6 coreclr!EEShutDownHelper + 0x2aa [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1310], calling coreclr!FinalizerThread::RaiseShutdownEvents [D:\a\_work\1\s\src\coreclr\vm\finalizerthread.h:52]
0517F0B8 708b3c8e coreclr!`anonymous namespace'::GetConfigDWORD + 0x23 [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:240], calling coreclr!`anonymous namespace'::EnvGetString [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:139]
0517F0C4 708b3ce9 coreclr!`anonymous namespace'::GetConfigDWORD + 0x7e [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:256], calling coreclr!_EH_epilog3 [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\eh\i386\ehprolg3.c:529]
0517F0F8 708b3ce9 coreclr!`anonymous namespace'::GetConfigDWORD + 0x7e [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:256], calling coreclr!_EH_epilog3 [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\eh\i386\ehprolg3.c:529]
0517F0FC 708b3c54 coreclr!CLRConfig::GetConfigValue + 0x1c [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:436], calling coreclr!`anonymous namespace'::GetConfigDWORD [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:222]
0517F11C 708edc00 coreclr!CorHost2::ExecuteAssembly + 0x190 [D:\a\_work\1\s\src\coreclr\vm\corhost.cpp:400], calling coreclr!_EH_epilog3 [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\eh\i386\ehprolg3.c:529]
0517F160 708cc452 coreclr!CrstBase::Leave + 0xa [D:\a\_work\1\s\src\coreclr\vm\crst.cpp:358], calling ntdll_77e10000!RtlLeaveCriticalSection
0517F190 7094a4db coreclr!AppDomainIterator::Next + 0x55 [D:\a\_work\1\s\src\coreclr\vm\appdomain.hpp:2987], calling coreclr!_EH_epilog3 [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\eh\i386\ehprolg3.c:529]
0517F194 7094a47e coreclr!MulticoreJitManager::StopProfileAll + 0x50 [D:\a\_work\1\s\src\coreclr\vm\multicorejit.cpp:1499], calling coreclr!_EH_epilog3 [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\eh\i386\ehprolg3.c:529]
0517F1C4 708ebc07 coreclr!EEShutDown + 0x66 [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1712], calling coreclr!EEShutDownHelper [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1215]
0517F1F4 709486e6 coreclr!CorHost2::UnloadAppDomain2 + 0x36 [D:\a\_work\1\s\src\coreclr\vm\corhost.cpp:922], calling coreclr!EEShutDown [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1671]
0517F200 70948594 coreclr!coreclr_shutdown_2 + 0x54 [D:\a\_work\1\s\src\coreclr\dlls\mscoree\unixinterface.cpp:357]
...

Thread 3:

0A7DFAA4 30ab98f4 (MethodDesc 0cd76b74 + 0x74 System.Threading.WaitHandle.WaitOneNoCheck(Int32)), calling 7090af60 (stub for System.Threading.WaitHandle.WaitOneCore(IntPtr, Int32))
0A7DFAD8 30a76baa (MethodDesc 0cd76c00 + 0xa System.Threading.WaitHandle.WaitOne()), calling (MethodDesc 0cd76b74 + 0 System.Threading.WaitHandle.WaitOneNoCheck(Int32))
0A7DFADC 6f904d85 (MethodDesc 174a6448 + 0xa5 Microsoft.Win32.SystemEvents.Shutdown()), calling 0535c12c
0A7DFB10 6f904df6 (MethodDesc 174a6458 + 0x6 Microsoft.Win32.SystemEvents.Shutdown(System.Object, System.EventArgs)), calling Microsoft_Win32_SystemEvents!System.Int32 Microsoft.Win32.SystemEvents+SystemEventInvokeInfo::GetHashCode()$##60000AF + 0x1d0
0A7DFB14 052dd338 052dd338
0A7DFB44 65ac1c25 (MethodDesc 07340258 + 0x55 System.AppContext.OnProcessExit())

Thread 6 (not quite sure how it got there?):

1A2EFAF0 765be69a user32!RealMsgWaitForMultipleObjectsEx + 0x7a, calling win32u!NtUserMsgWaitForMultipleObjectsEx
1A2EFB3C 2070fc52 (MethodDesc 1ecd9fa8 + 0x52 ILStubClass.IL_STUB_PInvoke(MSG ByRef, IntPtr, Int32, Int32, Int32))
1A2EFB64 765be5cc user32!MsgWaitForMultipleObjectsEx + 0x4c, calling user32!RealMsgWaitForMultipleObjectsEx
1A2EFB84 6f905245 (MethodDesc 174a6478 + 0x85 Microsoft.Win32.SystemEvents.WindowThreadProc())
1A2EFBB0 6f90523d (MethodDesc 174a6478 + 0x7d Microsoft.Win32.SystemEvents.WindowThreadProc()), calling coreclr!JIT_PInvokeBegin
1A2EFC10 65b86d71 (MethodDesc 174a7668 + 0x31 System.Threading.Thread+StartHelper.Callback(System.Object))
1A2EFC20 65b8f311 (MethodDesc 169fccec + 0x51 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object))
1A2EFC30 7095b0bd coreclr!ThePreStub + 0x11, calling coreclr!PreStubWorker [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp:1955]
1A2EFC54 65b85d72 (MethodDesc 0733f238 + 0x72 System.Threading.Thread.StartCallback()), calling (MethodDesc 169fccec + 0 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object))

Anyway, when the message loop in the separate thread is shutdown by external WM_QUIT message here:

if (msg.message == Interop.User32.WM_QUIT)
{
keepRunning = false;
break;
}

It reaches the end of the method and s_eventThreadTerminated does not exist yet:

if (s_eventThreadTerminated != null)
{
s_eventThreadTerminated.Set();
}

This can cause a race condition with the Shutdown method here:

s_eventThreadTerminated = new ManualResetEvent(false);

The s_eventThreadTerminated event is created. Another WM_QUIT is essentially sent into abyss. Then it waits for the s_eventThreadTerminated event which never gets set.

Now, this provably can happen but Thread 6 makes me doubt a bit that it's exactly what happened here.

Reproduction Steps

Subscribe an event on SystemEvents with a simple WinForms application. Kill the application through restart manager (eg. rmtool or other should be able to simulate it).

Expected behavior

No deadlock

Actual behavior

Deadlock

Regression?

Yes, .NET 6, likely triggered by #53467

Known Workarounds

No response

Configuration

.NET 6 RTM
Windows 10 (19041)
x86

Other information

No response

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 25, 2021
  2. filipnavara commented on Nov 25, 2021

    @filipnavara
    MemberAuthor
  3. filipnavara commented on Nov 25, 2021

    @filipnavara
    MemberAuthor

    Test project:
    rm.zip

    Run it, find the process id in Task Manager. Then run rmlogotest.exe <process id> (usually installed as part of Windows SDK under C:\Program Files (x86)\Windows Kits\10\App Certification Kit\rmlogotest.exe).

  4. filipnavara commented on Nov 25, 2021

    @filipnavara
    MemberAuthor

    The test app observes exactly the same deadlock as our app:

    ---------------------------------------------
    Thread   0
    Current frame: win32u!NtUserMsgWaitForMultipleObjectsEx + 0x14
    Child-SP         RetAddr          Caller, Callee
    000000B37AF7E540 00007ffa978ea5b7 combase!CCliModalLoop::BlockFn + 0x14f [onecore\com\combase\dcomrem\callctrl.cxx:2156], calling user32!MsgWaitForMultipleObjectsEx
    000000B37AF7E590 00007ffa97204957 ucrtbase!fflush + 0x17, calling ucrtbase!is_stream_flushable_or_commitable
    000000B37AF7E5B0 00007ffa978ea335 combase!CCliModalLoop::CCliModalLoop + 0x12d [onecore\com\combase\dcomrem\callctrl.hxx:685], calling combase!CCliModalLoop::IsAttachedQueuePointerMessageReorderingAllowed [onecore\com\combase\dcomrem\callctrl.hxx:420]
    000000B37AF7E5E0 00007ffa978e8f95 combase!ClassicSTAThreadWaitForHandles + 0xa5 [onecore\com\combase\dcomrem\classicsta.cpp:54], calling combase!CCliModalLoop::BlockFn [onecore\com\combase\dcomrem\callctrl.cxx:2036]
    000000B37AF7E610 00007ff9c11097a0 coreclr!SafeQueryInterface + 0x7c [D:\a\_work\1\s\src\coreclr\vm\interoputil.cpp:1146]
    000000B37AF7E700 00007ffa97909c50 combase!CoWaitForMultipleHandles + 0x80 [onecore\com\combase\dcomrem\sync.cxx:123], calling ntdll!LdrpDispatchUserCallTarget
    000000B37AF7E710 00007ff9c107df16 coreclr!Thread::GetFinalApartment + 0x12 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4944], calling coreclr!Thread::GetApartment [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4830]
    000000B37AF7E730 00007ff9c10ae213 coreclr!ThreadStore::WaitForOtherThreads + 0x8f [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:5802], calling coreclr!ThreadSuspend::UnlockThreadStore [D:\a\_work\1\s\src\coreclr\vm\threadsuspend.cpp:1905]
    000000B37AF7E740 00007ff9c1197e8f coreclr!Thread::DoAppropriateWaitWorker + 0x11a35f [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3517], calling combase!CoWaitForMultipleHandles [onecore\com\combase\dcomrem\sync.cxx:86]
    000000B37AF7E770 00007ffa9964e711 ntdll!RtlpFreeHeapInternal + 0x7c1, calling ntdll!RtlpHpStackLoggingEnabled
    000000B37AF7E830 00007ff9c107daf1 coreclr!Thread::DoAppropriateWait + 0x89 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3234], calling coreclr!Thread::DoAppropriateWaitWorker [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3438]
    000000B37AF7E8A0 00007ff9c10b6251 coreclr!ds_port_close + 0x25 [D:\a\_work\1\s\src\native\eventpipe\ds-ipc.c:618], calling coreclr!ds_ipc_close [D:\a\_work\1\s\src\native\eventpipe\ds-ipc-pal-namedpipe.c:534]
    000000B37AF7E8B0 00007ff9c110f4bd coreclr!FinalizerThread::RaiseShutdownEvents + 0x71 [D:\a\_work\1\s\src\coreclr\vm\finalizerthread.h:64], calling coreclr!Thread::DoAppropriateWait [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3208]
    000000B37AF7E8D0 00007ff9c10b620c coreclr!ds_ipc_stream_factory_shutdown + 0x50 [D:\a\_work\1\s\src\native\eventpipe\ds-ipc.c:515], calling coreclr!ds_port_close [D:\a\_work\1\s\src\native\eventpipe\ds-ipc.c:614]
    000000B37AF7E900 00007ff9c110eda3 coreclr!EEShutDownHelper + 0x423 [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1309], calling coreclr!FinalizerThread::RaiseShutdownEvents [D:\a\_work\1\s\src\coreclr\vm\finalizerthread.h:52]
    000000B37AF7EA00 00007ff9c1020821 coreclr!SetCommandLineArgs + 0x13d [D:\a\_work\1\s\src\coreclr\vm\corhost.cpp:293], calling coreclr!GCFrame::~GCFrame [D:\a\_work\1\s\src\coreclr\vm\frames.cpp:963]
    000000B37AF7EA60 00007ff9c102de6f coreclr!ClassLoader::LoadArrayTypeThrowing + 0xdf [D:\a\_work\1\s\src\coreclr\vm\clsload.cpp:4023], calling coreclr!__security_check_cookie [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\gs\amd64\amdsecgs.asm:45]
    000000B37AF7EAA0 00007ff9c10b5062 coreclr!`anonymous namespace'::GetConfigDWORD + 0x32 [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:240], calling coreclr!`anonymous namespace'::EnvGetString [D:\a\_work\1\s\src\coreclr\utilcode\clrconfig.cpp:139]
    000000B37AF7EB30 00007ff9c10ae556 coreclr!CorHost2::ExecuteAssembly + 0x1e6 [D:\a\_work\1\s\src\coreclr\vm\corhost.cpp:391], calling coreclr!GCFrame::~GCFrame [D:\a\_work\1\s\src\coreclr\vm\frames.cpp:963]
    000000B37AF7EBA0 00007ff9c1054c1a coreclr!CrstBase::Enter + 0x5a [D:\a\_work\1\s\src\coreclr\vm\crst.cpp:328], calling ntdll!RtlEnterCriticalSection
    000000B37AF7EBD0 00007ff9c1099233 coreclr!CrstBase::Leave + 0x13 [D:\a\_work\1\s\src\coreclr\vm\crst.cpp:358], calling ntdll!RtlLeaveCriticalSection
    000000B37AF7EC00 00007ff9c110f678 coreclr!AppDomainIterator::Next + 0x68 [D:\a\_work\1\s\src\coreclr\vm\appdomain.hpp:2986], calling coreclr!CrstBase::Leave [D:\a\_work\1\s\src\coreclr\vm\crst.cpp:340]
    000000B37AF7EC30 00007ff9c110f5d9 coreclr!MulticoreJitManager::StopProfileAll + 0x21 [D:\a\_work\1\s\src\coreclr\vm\multicorejit.cpp:1490], calling coreclr!AppDomainIterator::Next [D:\a\_work\1\s\src\coreclr\vm\appdomain.hpp:2960]
    000000B37AF7EC80 00007ff9c110e93e coreclr!EEShutDown + 0x66 [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1711], calling coreclr!EEShutDownHelper [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1215]
    000000B37AF7ECA0 00007ff9c10b5db0 coreclr!coreclr_execute_assembly + 0x100 [D:\a\_work\1\s\src\coreclr\dlls\mscoree\unixinterface.cpp:449], calling coreclr!ConstWStringArrayHolder::~ConstWStringArrayHolder [D:\a\_work\1\s\src\coreclr\dlls\mscoree\unixinterface.cpp:53]
    000000B37AF7ECC0 00007ff9c110e540 coreclr!CorHost2::UnloadAppDomain2 + 0x40 [D:\a\_work\1\s\src\coreclr\vm\corhost.cpp:922], calling coreclr!EEShutDown [D:\a\_work\1\s\src\coreclr\vm\ceemain.cpp:1671]
    000000B37AF7ECE0 00007ffa26a7b507 hostpolicy!mtx_do_lock + 0x15b [d:\a01\_work\2\s\src\vctools\crt\github\stl\src\mutex.cpp:162], calling hostpolicy!__security_check_cookie [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\gs\amd64\amdsecgs.asm:45]
    000000B37AF7ECF0 00007ff9c1120849 coreclr!coreclr_shutdown_2 + 0x59 [D:\a\_work\1\s\src\coreclr\dlls\mscoree\unixinterface.cpp:357], calling ntdll!LdrpDispatchUserCallTarget
    000000B37AF7ED10 00007ffa97204957 ucrtbase!fflush + 0x17, calling ucrtbase!is_stream_flushable_or_commitable
    000000B37AF7ED40 00007ffa26a59733 hostpolicy!run_app_for_context + 0x5e3 [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp:264], calling ntdll!LdrpDispatchUserCallTarget
    000000B37AF7EE40 00007ffa26a7b507 hostpolicy!mtx_do_lock + 0x15b [d:\a01\_work\2\s\src\vctools\crt\github\stl\src\mutex.cpp:162], calling hostpolicy!__security_check_cookie [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\gs\amd64\amdsecgs.asm:45]
    000000B37AF7EE50 00007ffa9964d411 ntdll!RtlFreeHeap + 0x51, calling ntdll!RtlpFreeHeapInternal
    000000B37AF7EE70 00007ffa26a7b60b hostpolicy!_Mtx_unlock + 0x1f [d:\a01\_work\2\s\src\vctools\crt\github\stl\src\mutex.cpp:172], calling ntdll!LdrpDispatchUserCallTarget
    000000B37AF7EEA0 00007ffa26a58d2b hostpolicy!`anonymous namespace'::get_hostpolicy_context + 0x11b [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp:167], calling hostpolicy!_Mtx_unlock [d:\a01\_work\2\s\src\vctools\crt\github\stl\src\mutex.cpp:164]
    000000B37AF7EEE0 00007ffa26a599ec hostpolicy!run_app + 0x3c [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp:284], calling hostpolicy!run_app_for_context [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp:207]
    000000B37AF7EF20 00007ffa26a5a387 hostpolicy!corehost_main + 0x107 [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp:430], calling hostpolicy!run_app [D:\a\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp:279]
    000000B37AF7F0D0 00007ffa7abab539 hostfxr!execute_app + 0x2e9 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:146], calling ntdll!LdrpDispatchUserCallTarget
    000000B37AF7F1D0 00007ffa7abae506 hostfxr!`anonymous namespace'::read_config_and_execute + 0xa6 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:533], calling hostfxr!execute_app [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:88]
    000000B37AF7F230 00007ffa9964d411 ntdll!RtlFreeHeap + 0x51, calling ntdll!RtlpFreeHeapInternal
    000000B37AF7F270 00007ffa972131ab ucrtbase!_free_base + 0x1b, calling ntdll!RtlFreeHeap
    000000B37AF7F2D0 00007ffa7abb0821 hostfxr!fx_muxer_t::handle_exec_host_command + 0x161 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:1018], calling hostfxr!`anonymous namespace'::read_config_and_execute [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:516]
    000000B37AF7F380 00007ffa7abaeb62 hostfxr!fx_muxer_t::execute + 0x482 [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:579], calling hostfxr!fx_muxer_t::handle_exec_host_command [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:1001]
    000000B37AF7F4C0 00007ffa7aba82ab hostfxr!hostfxr_main_startupinfo + 0xab [D:\a\_work\1\s\src\native\corehost\fxr\hostfxr.cpp:61], calling hostfxr!fx_muxer_t::execute [D:\a\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp:556]
    000000B37AF7F500 00007ffa96d5314a KERNELBASE!GetModuleHandleExW + 0x9a, calling ntdll!LdrAddRefDll
    000000B37AF7F510 00007ffa972131ab ucrtbase!_free_base + 0x1b, calling ntdll!RtlFreeHeap
    000000B37AF7F570 00007ffa96d1e80c KERNELBASE!GetProcAddressForCaller + 0x6c, calling ntdll!LdrGetProcedureAddressForCaller
    000000B37AF7F590 00007ffa97204957 ucrtbase!fflush + 0x17, calling ucrtbase!is_stream_flushable_or_commitable
    000000B37AF7F5C0 00007ff77c2f2008 rm_exe!exe_start + 0x8d8 [D:\workspace\_work\1\s\src\native\corehost\corehost.cpp:235], calling ntdll!LdrpDispatchUserCallTarget
    000000B37AF7F600 00007ffa9964e711 ntdll!RtlpFreeHeapInternal + 0x7c1, calling ntdll!RtlpHpStackLoggingEnabled
    000000B37AF7F790 00007ff77c2f237b rm_exe!wmain + 0xab [D:\workspace\_work\1\s\src\native\corehost\corehost.cpp:304], calling rm_exe!exe_start [D:\workspace\_work\1\s\src\native\corehost\corehost.cpp:97]
    000000B37AF7F7C0 00007ff77c2f3828 rm_exe!__scrt_common_main_seh + 0x10c [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288], calling rm_exe!wmain [D:\workspace\_work\1\s\src\native\corehost\corehost.cpp:283]
    000000B37AF7F800 00007ffa97e96ab0 kernel32!BaseThreadInitThunk + 0x10, calling kernel32!BaseThreadInitXfgThunk
    000000B37AF7F830 00007ffa99671edb ntdll!RtlUserThreadStart + 0x2b, calling ntdll!LdrpDispatchUserCallTarget
    ---------------------------------------------
    Thread   3
    Current frame: ntdll!NtWaitForMultipleObjects + 0x14
    Child-SP         RetAddr          Caller, Callee
    000000B37B87F300 00007ffa96d4a340 KERNELBASE!WaitForMultipleObjectsEx + 0xf0, calling ntdll!NtWaitForMultipleObjects
    000000B37B87F330 00007ffa9964f07a ntdll!RtlpAllocateHeapInternal + 0x12a, calling ntdll!RtlpLowFragHeapAllocFromContext
    000000B37B87F360 00007ffa9964f07a ntdll!RtlpAllocateHeapInternal + 0x12a, calling ntdll!RtlpLowFragHeapAllocFromContext
    000000B37B87F3A0 00007ffa96d4a438 KERNELBASE!WaitForMultipleObjectsEx + 0x1e8, calling ntdll!RtlActivateActivationContextUnsafeFast
    000000B37B87F400 00007ffa978ca023 combase!COleStaticMutexSem::Request + 0x83 [onecore\com\combase\common\internal\olesem.cxx:130], calling ntdll!RtlEnterCriticalSection
    000000B37B87F430 00007ffa978e7071 combase!TLSAddToMap + 0x75 [onecore\com\combase\tls\tls.cxx:186], calling combase!COleStaticMutexSem::Release [onecore\com\combase\common\internal\olesem.cxx:272]
    000000B37B87F460 00007ffa978e6fd4 combase!TLSPreallocateData + 0xb4 [onecore\com\combase\tls\tls.cxx:378], calling combase!TLSAddToMap [onecore\com\combase\tls\tls.cxx:158]
    000000B37B87F490 00007ffa978b3ffb combase!CObjectContext::QIHelper + 0x10b [onecore\com\combase\dcomrem\context.cxx:1724], calling ntdll!LdrpDispatchUserCallTarget
    000000B37B87F4C0 00007ff9c11097a0 coreclr!SafeQueryInterface + 0x7c [D:\a\_work\1\s\src\coreclr\vm\interoputil.cpp:1146]
    000000B37B87F4D0 00007ff9c1012805 coreclr!MethodDesc::DoBackpatch + 0x45 [D:\a\_work\1\s\src\coreclr\vm\prestub.cpp:93], calling coreclr!MethodDesc::IsEligibleForReJIT [D:\a\_work\1\s\src\coreclr\vm\method.hpp:1190]
    000000B37B87F4E0 00007ffa9964fa56 ntdll!RtlpLowFragHeapAllocFromContext + 0x1b6, calling ntdll!RtlpLfhFindClearBitAndSet
    000000B37B87F4F0 00007ffa9792700c combase!CObjectContext::GetCurrentThreadType + 0x1c [onecore\com\combase\dcomrem\context.cxx:4492], calling combase!IsApartmentInitialized [onecore\com\combase\class\compobj.cxx:4115]
    000000B37B87F520 00007ff9c110966e coreclr!GetCurrentThreadTypeNT5 + 0xfe [D:\a\_work\1\s\src\coreclr\vm\olecontexthelpers.cpp:132], calling ntdll!LdrpDispatchUserCallTarget
    000000B37B87F590 00007ff9c107dffe coreclr!Thread::GetApartmentRare + 0x4a [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4876], calling coreclr!GetCurrentThreadTypeNT5 [D:\a\_work\1\s\src\coreclr\vm\olecontexthelpers.cpp:108]
    000000B37B87F5C0 00007ff9c107df16 coreclr!Thread::GetFinalApartment + 0x12 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4944], calling coreclr!Thread::GetApartment [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4830]
    000000B37B87F5F0 00007ff9c107dc7f coreclr!Thread::DoAppropriateWaitWorker + 0x14f [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3517], calling kernel32!WaitForMultipleObjectsEx
    000000B37B87F630 00007ff9c1081fd7 coreclr!AllocateObject + 0x9b [D:\a\_work\1\s\src\coreclr\vm\gchelpers.cpp:993], calling coreclr!PublishObjectAndNotify<Object> [D:\a\_work\1\s\src\coreclr\vm\gchelpers.cpp:312]
    000000B37B87F680 00007ff9c107afa0 coreclr!Thread::GetExposedObject + 0x198 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4356], calling coreclr!GCFrame::~GCFrame [D:\a\_work\1\s\src\coreclr\vm\frames.cpp:963]
    000000B37B87F6E0 00007ff9c107daf1 coreclr!Thread::DoAppropriateWait + 0x89 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3234], calling coreclr!Thread::DoAppropriateWaitWorker [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3438]
    000000B37B87F760 00007ff9c107d660 coreclr!WaitHandleNative::CorWaitOneNative + 0xb0 [D:\a\_work\1\s\src\coreclr\vm\comwaithandle.cpp:31], calling coreclr!Thread::DoAppropriateWait [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:3208]
    000000B37B87F8A8 00007ff9c107d626 coreclr!WaitHandleNative::CorWaitOneNative + 0x76 [D:\a\_work\1\s\src\coreclr\vm\comwaithandle.cpp:24], calling coreclr!LazyMachStateCaptureState
    000000B37B87F8E0 00007ff996517caa (MethodDesc 00007ff96175a9c0 + 0x5a System.Threading.WaitHandle.WaitOneNoCheck(Int32)), calling 00007ff9c107d5b0 (stub for System.Threading.WaitHandle.WaitOneCore(IntPtr, Int32))
    000000B37B87F940 00007ff99651894f (MethodDesc 00007ff96175aa90 + 0xf System.Threading.WaitHandle.WaitOne()), calling 00007ff9618a07c0
    000000B37B87F970 00007ffa853a633a (MethodDesc 00007ff9616a4708 + 0xda Microsoft.Win32.SystemEvents.Shutdown()), calling 00007ff96154b010
    000000B37B87F9F0 00007ffa853a63ba (MethodDesc 00007ff9616a4720 + 0xa Microsoft.Win32.SystemEvents.Shutdown(System.Object, System.EventArgs)), calling Microsoft_Win32_SystemEvents!System.Int32 Microsoft.Win32.SystemEvents+SystemEventInvokeInfo::GetHashCode()$##60000AF + 0x200
    000000B37B87FA20 00007ff9615e0c88 (MethodDesc 00007ff961786be8 + 0x48 ILStubClass.IL_STUB_MulticastDelegate_Invoke(System.Object, System.EventArgs))
    000000B37B87FA70 00007ff99643b87e (MethodDesc 00007ff961671100 + 0x5e System.AppContext.OnProcessExit())
    000000B37B87FAB0 00007ff9c11337e3 coreclr!CallDescrWorkerInternal + 0x83
    000000B37B87FAB8 00007ff9c104e010 coreclr!MethodDescCallSite::CallTargetWorker + 0x80 [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:384], calling coreclr!__chkstk [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\misc\amd64\chkstk.asm:67]
    000000B37B87FAF0 00007ff9c104e106 coreclr!MethodDescCallSite::CallTargetWorker + 0x176 [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:551], calling coreclr!CallDescrWorkerWithHandler [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:54]
    000000B37B87FB60 00007ff9c104e010 coreclr!MethodDescCallSite::CallTargetWorker + 0x80 [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:384], calling coreclr!__chkstk [d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\misc\amd64\chkstk.asm:67]
    000000B37B87FC20 00007ff9c10f335b coreclr!FinalizerThread::FinalizerThreadStart + 0xcb [D:\a\_work\1\s\src\coreclr\vm\finalizerthread.cpp:401], calling coreclr!MethodDescCallSite::CallTargetWorker [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:262]
    000000B37B87FD30 00007ffa97e96ab0 kernel32!BaseThreadInitThunk + 0x10, calling kernel32!BaseThreadInitXfgThunk
    000000B37B87FD60 00007ffa99671edb ntdll!RtlUserThreadStart + 0x2b, calling ntdll!LdrpDispatchUserCallTarget
    ---------------------------------------------
    Thread   4
    Current frame: win32u!NtUserMsgWaitForMultipleObjectsEx + 0x14
    Child-SP         RetAddr          Caller, Callee
    000000B37BB7F940 00007ffa853a6e96 (MethodDesc 00007ff9617787a8 + 0x56 Interop+User32.MsgWaitForMultipleObjectsEx(Int32, IntPtr, Int32, Int32, Int32))
    000000B37BB7F9A0 00007ffa853a6e7e (MethodDesc 00007ff9617787a8 + 0x3e Interop+User32.MsgWaitForMultipleObjectsEx(Int32, IntPtr, Int32, Int32, Int32)), calling coreclr!JIT_PInvokeBegin
    000000B37BB7F9B8 00007ff9c107d8b8 coreclr!ThreadNative::Sleep + 0x68 [D:\a\_work\1\s\src\coreclr\vm\comsynchronizable.cpp:467], calling coreclr!LazyMachStateCaptureState
    000000B37BB7FA20 00007ffa853a6972 (MethodDesc 00007ff9616a4750 + 0x92 Microsoft.Win32.SystemEvents.WindowThreadProc()), calling 00007ff9615dd410 (stub for Interop+User32.MsgWaitForMultipleObjectsEx(Int32, IntPtr, Int32, Int32, Int32))
    000000B37BB7FAA0 00007ff99651205f (MethodDesc 00007ff96166f870 + 0x3f System.Threading.Thread.StartCallback())
    000000B37BB7FAE0 00007ff9c11337e3 coreclr!CallDescrWorkerInternal + 0x83
    000000B37BB7FAF0 00007ff9c107bd79 coreclr!Thread::AllocateIOCompletionContext + 0x25 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:1982], calling ntdll!RtlAllocateHeap
    000000B37BB7FB20 00007ff9c104c514 coreclr!DispatchCallSimple + 0x80 [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:220], calling coreclr!CallDescrWorkerWithHandler [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:54]
    000000B37BB7FB40 00007ff9c10c85f1 coreclr!MethodDesc::TryGetMultiCallableAddrOfCode + 0x75 [D:\a\_work\1\s\src\coreclr\vm\method.cpp:2202], calling coreclr!MethodDesc::GetMethodEntryPoint [D:\a\_work\1\s\src\coreclr\vm\method.cpp:541]
    000000B37BB7FB70 00007ff9c10c8526 coreclr!MethodDesc::GetMultiCallableAddrOfCode + 0x12 [D:\a\_work\1\s\src\coreclr\vm\method.cpp:2071], calling coreclr!MethodDesc::TryGetMultiCallableAddrOfCode [D:\a\_work\1\s\src\coreclr\vm\method.cpp:2113]
    000000B37BB7FBB0 00007ff9c1118883 coreclr!ThreadNative::KickOffThread_Worker + 0x63 [D:\a\_work\1\s\src\coreclr\vm\comsynchronizable.cpp:158], calling coreclr!DispatchCallSimple [D:\a\_work\1\s\src\coreclr\vm\callhelpers.cpp:173]
    000000B37BB7FBE0 00007ff9c107bd79 coreclr!Thread::AllocateIOCompletionContext + 0x25 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:1982], calling ntdll!RtlAllocateHeap
    000000B37BB7FC10 00007ff9c107f921 coreclr!ManagedThreadBase_DispatchMiddle + 0x85 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:7356], calling ntdll!LdrpDispatchUserCallTarget
    000000B37BB7FC30 00007ff9c107b8ee coreclr!ETW::ThreadLog::FireThreadCreated + 0x36 [D:\a\_work\1\s\src\coreclr\vm\eventtrace.cpp:2604], calling coreclr!FireEtwThreadCreated [D:\a\_work\1\s\artifacts\obj\coreclr\windows.x64.Release\inc\clretwallmain.h:1660]
    000000B37BB7FC40 00007ff9c107ba15 coreclr!Thread::PrepareApartmentAndContext + 0x3d [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4805], calling coreclr!Thread::SetApartment [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:4976]
    000000B37BB7FC50 00007ff9c107ba95 coreclr!ThreadStore::TransferStartedThread + 0x69 [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:5474], calling coreclr!ThreadSuspend::UnlockThreadStore [D:\a\_work\1\s\src\coreclr\vm\threadsuspend.cpp:1905]
    000000B37BB7FCF0 00007ff9c107f9fa coreclr!ManagedThreadBase_DispatchOuter + 0xae [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:7515], calling coreclr!ManagedThreadBase_DispatchMiddle [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:7316]
    000000B37BB7FD90 00007ff9c107b719 coreclr!ThreadNative::KickOffThread + 0x79 [D:\a\_work\1\s\src\coreclr\vm\comsynchronizable.cpp:230], calling coreclr!ManagedThreadBase_DispatchOuter [D:\a\_work\1\s\src\coreclr\vm\threads.cpp:7467]
    000000B37BB7FDF0 00007ffa97e96ab0 kernel32!BaseThreadInitThunk + 0x10, calling kernel32!BaseThreadInitXfgThunk
    000000B37BB7FE20 00007ffa99671edb ntdll!RtlUserThreadStart + 0x2b, calling ntdll!LdrpDispatchUserCallTarget
    
  5. added this to the 7.0.0 milestone on Dec 10, 2021
  6. filipnavara commented on Dec 14, 2021

    @filipnavara
    MemberAuthor

    Just realized that the window handle is not passed to the call on these lines, so the WM_QUIT message is never processed:

    int ret = Interop.User32.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 100, Interop.User32.QS_ALLINPUT, Interop.User32.MWMO_INPUTAVAILABLE);

    while (Interop.User32.PeekMessageW(ref msg, IntPtr.Zero, 0, 0, Interop.User32.PM_REMOVE))


    Nevermind, that's probably not the cause even if it's highly unusual. The PostMessageW call in Shutdown fails (return value is not checked) when shutting down through restart manager. When shutting down the application normally it works though.

  7. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Dec 14, 2021
  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Dec 14, 2021
  9. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 26, 2022
  10. ghost locked as resolved and limited conversation to collaborators on Feb 26, 2022
  11. modified the milestones: 7.0.0, 6.0.x on Mar 4, 2022
  12. reopened this on Mar 4, 2022
  13. ericstj commented on Mar 4, 2022

    @ericstj
    Member

    Reopening for backport to 6.0.

  14. akoeplinger commented on Mar 11, 2022

    @akoeplinger
    Member

    The 6.0 backport was merged: #66230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions