Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase stack size for IIS Inprocess #10511

Merged
merged 2 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define CS_ASPNETCORE_DISABLE_START_UP_ERROR_PAGE L"disableStartUpErrorPage"
#define CS_ENABLED L"enabled"
#define CS_ASPNETCORE_HANDLER_CALL_STARTUP_HOOK L"callStartupHook"
#define CS_ASPNETCORE_HANDLER_STACK_SIZE L"stackSize"

class ConfigurationSection: NonCopyable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ InProcessOptions::InProcessOptions(const ConfigurationSource &configurationSourc
const auto handlerSettings = aspNetCoreSection->GetKeyValuePairs(CS_ASPNETCORE_HANDLER_SETTINGS);
m_fSetCurrentDirectory = equals_ignore_case(find_element(handlerSettings, CS_ASPNETCORE_HANDLER_SET_CURRENT_DIRECTORY).value_or(L"true"), L"true");
m_fCallStartupHook = equals_ignore_case(find_element(handlerSettings, CS_ASPNETCORE_HANDLER_CALL_STARTUP_HOOK).value_or(L"true"), L"true");
m_strStackSize = find_element(handlerSettings, CS_ASPNETCORE_HANDLER_STACK_SIZE).value_or(L"1048576");

m_dwStartupTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_STARTUP_TIME_LIMIT) * 1000;
m_dwShutdownTimeLimitInMS = aspNetCoreSection->GetRequiredLong(CS_ASPNETCORE_PROCESS_SHUTDOWN_TIME_LIMIT) * 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class InProcessOptions: NonCopyable
return m_bindingInformation;
}

std::wstring
jkotalik marked this conversation as resolved.
Show resolved Hide resolved
QueryStackSize() const
{
return m_strStackSize;
}

InProcessOptions(const ConfigurationSource &configurationSource, IHttpSite* pSite);

static
Expand All @@ -125,6 +131,7 @@ class InProcessOptions: NonCopyable
std::wstring m_strArguments;
std::wstring m_strProcessPath;
std::wstring m_struStdoutLogFile;
std::wstring m_strStackSize;
bool m_fStdoutLogEnabled;
bool m_fDisableStartUpErrorPage;
bool m_fSetCurrentDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ IN_PROCESS_APPLICATION::ExecuteApplication()

// Used to make .NET Runtime always log to event log when there is an unhandled exception.
LOG_LAST_ERROR_IF(!SetEnvironmentVariable(L"COMPlus_UseEntryPointFilter", L"1"));
LOG_LAST_ERROR_IF(!SetEnvironmentVariable(L"COMPlus_DefaultStackSize", m_pConfig->QueryStackSize().c_str()));

bool clrThreadExited;
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,28 @@ public async Task ExceptionIsLoggedToEventLogDoesNotWriteToResponse()
VerifyDotnetRuntimeEventLog(deploymentResult);
}

[ConditionalFact]
[RequiresNewHandler]
public async Task StackOverflowIsAvoidedBySettingLargerStack()
{
var deploymentParameters = Fixture.GetBaseDeploymentParameters();
var deploymentResult = await DeployAsync(deploymentParameters);
var result = await deploymentResult.HttpClient.GetAsync("/StackSize");
Assert.True(result.IsSuccessStatusCode);
}

[ConditionalFact]
[RequiresNewHandler]
public async Task StackOverflowCanBeSetBySettingLargerStackViaHandlerSetting()
{
var deploymentParameters = Fixture.GetBaseDeploymentParameters();
deploymentParameters.HandlerSettings["stackSize"] = "10000000";

var deploymentResult = await DeployAsync(deploymentParameters);
var result = await deploymentResult.HttpClient.GetAsync("/StackSizeLarge");
Assert.True(result.IsSuccessStatusCode);
}

private static void VerifyDotnetRuntimeEventLog(IISDeploymentResult deploymentResult)
{
var entries = GetEventLogsFromDotnetRuntime(deploymentResult);
Expand Down
23 changes: 23 additions & 0 deletions src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,29 @@ private async Task ShutdownStopAsyncWithCancelledToken(HttpContext ctx)
await server.StopAsync(cts.Token);
}

private async Task StackSize(HttpContext ctx)
{
// This would normally stackoverflow if we didn't increase the stack size per thread.
RecursiveFunction(10000);
await ctx.Response.WriteAsync("Hello World");
}

private async Task StackSizeLarge(HttpContext ctx)
{
// This would normally stackoverflow if we didn't increase the stack size per thread.
RecursiveFunction(30000);
await ctx.Response.WriteAsync("Hello World");
}

private void RecursiveFunction(int i)
{
if (i == 0)
jkotalik marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}
RecursiveFunction(i - 1);
}

private async Task GetServerVariableStress(HttpContext ctx)
{
// This test simulates the scenario where native Flush call is being
Expand Down