Skip to content

Commit bdcf921

Browse files
committed
Wait for initialization or exit before calling shutdown
1 parent 519b8b9 commit bdcf921

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ IN_PROCESS_APPLICATION::StopClr()
6868
// This has the state lock around it.
6969
LOG_INFO(L"Stopping CLR");
7070

71-
if (!m_blockManagedCallbacks)
71+
// Signal shutdown
72+
if (m_pShutdownEvent != nullptr)
73+
{
74+
LOG_IF_FAILED(SetEvent(m_pShutdownEvent));
75+
}
76+
77+
// Need to wait for either the app to be initialized, the worker thread to exit, or the shutdown timeout.
78+
const HANDLE waitHandles[2] = { m_pInitializeEvent, m_workerThread.native_handle() };
79+
80+
const auto waitResult = WaitForMultipleObjects(2, waitHandles, FALSE, m_pConfig->QueryShutdownTimeLimitInMS());
81+
82+
if (!m_blockManagedCallbacks && waitResult != WAIT_OBJECT_0 + 1)
7283
{
7384
// We cannot call into managed if the dll is detaching from the process.
7485
// Calling into managed code when the dll is detaching is strictly a bad idea,
@@ -90,12 +101,6 @@ IN_PROCESS_APPLICATION::StopClr()
90101
}
91102
}
92103

93-
// Signal shutdown
94-
if (m_pShutdownEvent != nullptr)
95-
{
96-
LOG_IF_FAILED(SetEvent(m_pShutdownEvent));
97-
}
98-
99104
if (m_workerThread.joinable())
100105
{
101106
// Worker thread would wait for clr to finish and log error if required

0 commit comments

Comments
 (0)