Skip to content

Commit f7fbf14

Browse files
committed
fixup
1 parent bb29868 commit f7fbf14

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationmanager.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ APPLICATION_MANAGER::GetOrCreateApplicationInfo(
2323
)
2424
{
2525
// GetOrCreateApplicationInfo is called from proxymodule when a request is received.
26-
// Set this value to indicate that a request has been received so we can disable shutdown logic in OnGlobalApplicationStop
27-
m_hasStarted = true;
2826

27+
PCWSTR pszVariableValue = nullptr;
28+
DWORD cbLength = 0;
29+
// Check for preload or warmup request, part of the application initialization process, see comments in ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop for more info
30+
if (FAILED(pHttpContext.GetServerVariable("PRELOAD_REQUEST", &pszVariableValue, &cbLength)) &&
31+
FAILED(pHttpContext.GetServerVariable("WARMUP_REQUEST", &pszVariableValue, &cbLength)))
32+
{
33+
// Set this value to indicate that a request has been received so we can disable shutdown logic in OnGlobalApplicationStop
34+
m_hasStarted = true;
35+
}
2936
auto &pApplication = *pHttpContext.GetApplication();
3037

3138
// The configuration path is unique for each application and is used for the

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/globalmodule.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ ASPNET_CORE_GLOBAL_MODULE::OnGlobalStopListening(
3535
return GL_NOTIFICATION_CONTINUE;
3636
}
3737

38+
// We prefer shutting down from OnGlobalStopListening as it is called right before the IIS request handler is disabled, which means it'll start queueing requests
39+
// But if we stopped in OnGlobalApplicationStop then we can start shutting down while the request handler is still active resulting in us returning 503's since we're shutting down.
40+
// We still need to shutdown in specific cases where OnGlobalStopListening isn't called, like IISExpress or if the app never receives a request (app preload).
3841
GLOBAL_NOTIFICATION_STATUS
3942
ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop(
4043
IN IHttpApplicationStopProvider* pProvider
@@ -51,17 +54,19 @@ ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop(
5154

5255
LOG_INFO(L"ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop");
5356

54-
if (!g_fInShutdown && !m_shutdown.joinable()
55-
&& (m_pApplicationManager->IsIISExpress() || !m_pApplicationManager->HasReceivedRequest()))
57+
if (!g_fInShutdown && !m_shutdown.joinable())
5658
{
57-
// Apps with preload + always running that don't receive a request before recycle/shutdown will never call OnGlobalStopListening
58-
// IISExpress can also close without calling OnGlobalStopListening which is where we usually would trigger shutdown
59-
// so we should make sure to shutdown the server in those cases
60-
StartShutdown();
61-
}
62-
else
63-
{
64-
LOG_INFO(L"Ignoring OnGlobalApplicationStop, OnGlobalStopListening should be called shortly.");
59+
if ((m_pApplicationManager->IsIISExpress() || !m_pApplicationManager->HasReceivedRequest()))
60+
{
61+
// Apps with preload + always running that don't receive a request before recycle/shutdown will never call OnGlobalStopListening
62+
// IISExpress can also close without calling OnGlobalStopListening which is where we usually would trigger shutdown
63+
// so we should make sure to shutdown the server in those cases
64+
StartShutdown();
65+
}
66+
else
67+
{
68+
LOG_INFO(L"Ignoring OnGlobalApplicationStop, OnGlobalStopListening has been called or should be called shortly.");
69+
}
6570
}
6671

6772
return GL_NOTIFICATION_CONTINUE;

src/Servers/IIS/IntegrationTesting.IIS/src/IISDeployer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,14 @@ private static Site FindSite(ServerManager serverManager, string contentRoot)
307307

308308
private void AddTemporaryAppHostConfig(string contentRoot, int port)
309309
{
310-
var multiSite = true;
310+
var multiSite = _applicationHostConfig is not null;
311311
XDocument config;
312312
if (_applicationHostConfig is not null)
313313
{
314314
config = XDocument.Parse(File.ReadAllText(_applicationHostConfig));
315315
}
316316
else
317317
{
318-
multiSite = false;
319318
_configPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D"));
320319
_applicationHostConfig = Path.Combine(_configPath, "applicationHost.config");
321320
Directory.CreateDirectory(_configPath);

0 commit comments

Comments
 (0)