Skip to content

Commit bc058fd

Browse files
committed
Add opt out switch
1 parent 329403c commit bc058fd

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ConfigurationSection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define CS_ENABLED L"enabled"
3131
#define CS_ASPNETCORE_HANDLER_CALL_STARTUP_HOOK L"callStartupHook"
3232
#define CS_ASPNETCORE_HANDLER_STACK_SIZE L"stackSize"
33+
#define CS_ASPNETCORE_DISABLE_RECYCLE_ON_STARTUP_TIMEOUT L"disableRecycleOnStartupTimeout"
3334
#define CS_ASPNETCORE_DETAILEDERRORS L"ASPNETCORE_DETAILEDERRORS"
3435
#define CS_ASPNETCORE_ENVIRONMENT L"ASPNETCORE_ENVIRONMENT"
3536
#define CS_DOTNET_ENVIRONMENT L"DOTNET_ENVIRONMENT"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ InProcessOptions::InProcessOptions(const ConfigurationSource &configurationSourc
6666
m_fSetCurrentDirectory = equals_ignore_case(find_element(handlerSettings, CS_ASPNETCORE_HANDLER_SET_CURRENT_DIRECTORY).value_or(L"true"), L"true");
6767
m_fCallStartupHook = equals_ignore_case(find_element(handlerSettings, CS_ASPNETCORE_HANDLER_CALL_STARTUP_HOOK).value_or(L"true"), L"true");
6868
m_strStackSize = find_element(handlerSettings, CS_ASPNETCORE_HANDLER_STACK_SIZE).value_or(L"1048576");
69+
m_fDisableRecycleOnStartupTimeout = equals_ignore_case(find_element(handlerSettings, CS_ASPNETCORE_DISABLE_RECYCLE_ON_STARTUP_TIMEOUT).value_or(L"false"), L"true");
6970

7071
m_dwStartupTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_STARTUP_TIME_LIMIT) * 1000;
7172
m_dwShutdownTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_SHUTDOWN_TIME_LIMIT) * 1000;

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/InProcessOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class InProcessOptions: NonCopyable
118118
return m_strStackSize;
119119
}
120120

121+
bool
122+
QueryDisableRecycleOnStartupTimeout() const
123+
{
124+
return m_fDisableRecycleOnStartupTimeout;
125+
}
126+
121127
InProcessOptions(const ConfigurationSource &configurationSource, IHttpSite* pSite);
122128

123129
static
@@ -139,6 +145,7 @@ class InProcessOptions: NonCopyable
139145
bool m_fWindowsAuthEnabled;
140146
bool m_fBasicAuthEnabled;
141147
bool m_fAnonymousAuthEnabled;
148+
bool m_fDisableRecycleOnStartupTimeout;
142149
DWORD m_dwStartupTimeLimitInMS;
143150
DWORD m_dwShutdownTimeLimitInMS;
144151
DWORD m_dwMaxRequestBodySize;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ IN_PROCESS_APPLICATION::LoadManagedApplication(ErrorContext& errorContext)
169169
errorContext.errorReason = format("ASP.NET Core app failed to start after %d milliseconds", m_pConfig->QueryStartupTimeLimitInMS());
170170

171171
m_waitForShutdown = false;
172-
Stop(/* fServerInitiated */false);
172+
if (m_pConfig->QueryDisableRecycleOnStartupTimeout())
173+
{
174+
StopClr();
175+
}
176+
else
177+
{
178+
Stop(/* fServerInitiated */false);
179+
}
173180
throw InvalidOperationException(format(L"Managed server didn't initialize after %u ms.", m_pConfig->QueryStartupTimeLimitInMS()));
174181
}
175182

src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupTests.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,40 @@ public async Task StartupTimeoutIsApplied()
470470
var response = await deploymentResult.HttpClient.GetAsync("/");
471471
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
472472

473+
// Startup timeout now recycles process.
473474
deploymentResult.AssertWorkerProcessStop();
474-
//StopServer(gracefulShutdown: false);
475+
476+
EventLogHelpers.VerifyEventLogEvent(deploymentResult,
477+
EventLogHelpers.InProcessFailedToStart(deploymentResult, "Managed server didn't initialize after 1000 ms."),
478+
Logger);
479+
480+
if (DeployerSelector.HasNewHandler)
481+
{
482+
var responseContent = await response.Content.ReadAsStringAsync();
483+
Assert.Contains("500.37", responseContent);
484+
}
485+
}
486+
}
487+
488+
[ConditionalFact]
489+
public async Task StartupTimeoutIsApplied_DisableRecycleOnStartupTimeout()
490+
{
491+
// From what we can tell, this failure is due to ungraceful shutdown.
492+
// The error could be the same as https://github.com/dotnet/core-setup/issues/4646
493+
// But can't be certain without another repro.
494+
using (AppVerifier.Disable(DeployerSelector.ServerType, 0x300))
495+
{
496+
var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite);
497+
deploymentParameters.TransformArguments((a, _) => $"{a} Hang");
498+
deploymentParameters.WebConfigActionList.Add(
499+
WebConfigHelpers.AddOrModifyAspNetCoreSection("startupTimeLimit", "1"));
500+
deploymentParameters.HandlerSettings["disableRecycleOnStartupTimeout"] = "true";
501+
var deploymentResult = await DeployAsync(deploymentParameters);
502+
503+
var response = await deploymentResult.HttpClient.GetAsync("/");
504+
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
505+
506+
StopServer(gracefulShutdown: false);
475507

476508
EventLogHelpers.VerifyEventLogEvent(deploymentResult,
477509
EventLogHelpers.InProcessFailedToStart(deploymentResult, "Managed server didn't initialize after 1000 ms."),

0 commit comments

Comments
 (0)