Skip to content

Commit 79e8659

Browse files
[release/8.0] Fix app_offline detection for some OSes (#52810)
* Fix app_offline detection for some OSes * save --------- Co-authored-by: Brennan Conroy <[email protected]>
1 parent d0c055d commit 79e8659

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ FILE_WATCHER::FILE_WATCHER() :
2121
FALSE, // not set
2222
nullptr); // name
2323

24-
m_pShutdownEvent = CreateEvent(
25-
nullptr, // default security attributes
26-
TRUE, // manual reset event
27-
FALSE, // not set
28-
nullptr); // name
29-
3024
// Use of TerminateThread for the file watcher thread was eliminated in favor of an event-based
3125
// approach. Out of an abundance of caution, we are temporarily adding an environment variable
3226
// to allow falling back to TerminateThread usage. If all goes well, this will be removed in a
@@ -175,19 +169,8 @@ Win32 error
175169
LOG_INFO(L"Starting file watcher thread");
176170
DBG_ASSERT(pFileMonitor != nullptr);
177171

178-
HANDLE events[2] = { pFileMonitor->m_hCompletionPort, pFileMonitor->m_pShutdownEvent };
179-
180-
DWORD dwEvent = 0;
181172
while (true)
182173
{
183-
// Wait for either a change notification or a shutdown event.
184-
dwEvent = WaitForMultipleObjects(ARRAYSIZE(events), events, FALSE, INFINITE) - WAIT_OBJECT_0;
185-
186-
if (dwEvent == 1)
187-
{
188-
// Shutdown event.
189-
break;
190-
}
191174

192175
DWORD cbCompletion = 0;
193176
OVERLAPPED* pOverlapped = nullptr;
@@ -203,6 +186,11 @@ Win32 error
203186
DBG_ASSERT(success);
204187
(void)success;
205188

189+
if (completionKey == FILE_WATCHER_SHUTDOWN_KEY)
190+
{
191+
break;
192+
}
193+
206194
DBG_ASSERT(pOverlapped != nullptr);
207195
if (pOverlapped != nullptr)
208196
{
@@ -469,7 +457,7 @@ FILE_WATCHER::StopMonitor()
469457
LOG_INFO(L"Stopping file watching.");
470458

471459
// Signal the file watcher thread to exit
472-
SetEvent(m_pShutdownEvent);
460+
PostQueuedCompletionStatus(m_hCompletionPort, 0, FILE_WATCHER_SHUTDOWN_KEY, NULL);
473461
WaitForWatcherThreadExit();
474462

475463
if (m_fShadowCopyEnabled)

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class FILE_WATCHER{
6060
HandleWrapper<NullHandleTraits> m_hChangeNotificationThread;
6161
HandleWrapper<NullHandleTraits> _hDirectory;
6262
HandleWrapper<NullHandleTraits> m_pDoneCopyEvent;
63-
HandleWrapper<NullHandleTraits> m_pShutdownEvent;
6463
std::atomic_bool m_fThreadExit;
6564
STTIMER m_Timer;
6665
SRWLOCK m_copyLock{};

0 commit comments

Comments
 (0)