Skip to content

Migrate IIS in-process handler from DEFAULT_STACK_SIZE to System.Threading.DefaultStackSize#65737

Merged
MichalStrehovsky merged 4 commits intomainfrom
copilot/update-default-stack-size
Mar 16, 2026
Merged

Migrate IIS in-process handler from DEFAULT_STACK_SIZE to System.Threading.DefaultStackSize#65737
MichalStrehovsky merged 4 commits intomainfrom
copilot/update-default-stack-size

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

DEFAULT_STACK_SIZE host configuration option is being removed in dotnet/runtime#118057. Migrates the IIS in-process request handler to the replacement System.Threading.DefaultStackSize property, which requires a decimal string instead of hex.

Description

  • HostFxr.h: Update DOTNETCORE_STACK_SIZE macro value from L"DEFAULT_STACK_SIZE"L"System.Threading.DefaultStackSize"
  • InProcessOptions.cpp: Parse the configured stack size (hex with or without 0x prefix, preserving backward compat) via wcstoul(..., 16) and store as decimal string. Default changes from L"0x100000"L"1048576" (both 1 MB). For invalid or out-of-range values, the raw configured string is passed through as-is so the runtime handles it the same way as before.
// Before
m_strStackSize = find_element(handlerSettings, CS_ASPNETCORE_HANDLER_STACK_SIZE).value_or(L"0x100000");

// After — converts hex config value to decimal required by new API;
// passes through raw value on parse failure to match previous runtime behavior
unsigned long stackSizeVal = wcstoul(rawStr, &endPtr, 16);
if (endPtr != rawStr && errno == 0)
{
    swprintf_s(decimalBuf, L"%lu", stackSizeVal);
    m_strStackSize = decimalBuf;  // e.g. "0x100000" or "100000" → "1048576"
}
else
{
    m_strStackSize = rawStackSize.value();  // pass through, let runtime handle it
}

No changes needed at the call site in inprocessapplication.cpp.

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.
Original prompt

Background

The DEFAULT_STACK_SIZE host configuration option (used via the DOTNETCORE_STACK_SIZE macro) is being deleted in dotnet/runtime#118057. We need to migrate to the replacement System.Threading.DefaultStackSize host configuration option, which is documented in dotnet/docs#47575.

What needs to change

There are three files involved across the IIS in-process request handler:


1. src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxr.h

Current:

#define DOTNETCORE_STACK_SIZE L"DEFAULT_STACK_SIZE"

Change to:

#define DOTNETCORE_STACK_SIZE L"System.Threading.DefaultStackSize"

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

The stack size value is currently stored as a hex string (with optional 0x prefix) — matching what DEFAULT_STACK_SIZE expected. The new System.Threading.DefaultStackSize property requires a decimal number string.

Current (line 68):

m_strStackSize = find_element(handlerSettings, CS_ASPNETCORE_HANDLER_STACK_SIZE).value_or(L"0x100000"); // 1 MB in hex

The default 0x100000 hex = 1048576 decimal (1 MB).

Change to: Parse the configured value (which may be hex with or without 0x prefix, as before) and convert it to a decimal string. The default should become L"1048576" (decimal equivalent of 0x100000).

The logic should be:

  1. Read the raw string value from handler settings (same key CS_ASPNETCORE_HANDLER_STACK_SIZE).
  2. If the raw value starts with 0x or 0X, parse it as hexadecimal (using wcstoul with base 16) and convert to a decimal wide string.
  3. If it doesn't have a 0x prefix but is a valid hex string (the old format allowed hex without the prefix), try parsing it as hexadecimal first (base 16), then convert to decimal.
    • Actually, to keep it simple and match the old behavior: attempt to parse the value as hex (base 16) regardless, since DEFAULT_STACK_SIZE accepted hex with or without 0x prefix. Then format the result as decimal.
  4. Store the decimal string in m_strStackSize.
  5. The default (when no value is configured) should be L"1048576" (1 MB in decimal).

Here's a concrete implementation approach:

// Parse stack size: config accepts hex (with or without 0x prefix), new API requires decimal
auto rawStackSize = find_element(handlerSettings, CS_ASPNETCORE_HANDLER_STACK_SIZE);
if (rawStackSize.has_value())
{
    const wchar_t* rawStr = rawStackSize.value().c_str();
    wchar_t* endPtr = nullptr;
    // wcstoul handles "0x..." prefix automatically with base 0 or base 16
    // Use base 0 to auto-detect 0x prefix; fall back to base 16 for bare hex
    unsigned long stackSizeVal = wcstoul(rawStr, &endPtr, 16);
    wchar_t decimalBuf[32];
    swprintf_s(decimalBuf, L"%lu", stackSizeVal);
    m_strStackSize = decimalBuf;
}
else
{
    m_strStackSize = L"1048576"; // 1 MB in decimal
}

Note: The old DEFAULT_STACK_SIZE accepted hex with or without 0x prefix. Using base 16 in wcstoul handles both bare hex (e.g. "100000") and prefixed hex (e.g., "0x100000"). The new System.Threading.DefaultStackSize requires decimal, so we convert.


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

The QueryStackSize() return type and storage can remain std::wstring — no changes needed here. However, if there are any comments referencing hex or the old format, update them for clarity.


Summary of the change

Location Old New
HostFxr.h macro L"DEFAULT_STACK_SIZE" L"System.Threading.DefaultStackSize"
InProcessOptions.cpp default value L"0x100000" (hex string) L"1048576" (decimal string)
InProcessOptions.cpp value parsing stored raw hex string parse hex, store as decimal string

The inprocessapplication.cpp call site (context->m_hostFxr.SetRuntimePropertyValue(DOTNETCORE_STACK_SIZE, m_pConfig->QueryStackSize().c_str())) does not need to change — it will automatically pick up the new property name via the updated macro and receive the correctly formatted decimal value from QueryStackSize().

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: we currently set the DEFAULT_STACK_SIZE host configuration option to set the stack size. the DEFAULT_STACK_SIZE host configuration option is going to be deleted in @dotnet/runtime/pull/118057

We need to switch to the documented System.Threading.DefaultStackSize host configuration option (docs at @dotnet/docs/pull/47575). These settings are largely equivalent, we just need to swap the DEFAULT_STACK_SIZE string for System.Threading.DefaultStackSize string. Note however that System.Threading.DefaultStackSize accepts the setting as a decimal number. DEFAULT_STACK_SIZE accepted a hexadecimal number with or wi...

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…host config option

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Update host configuration for default stack size Migrate IIS in-process handler from DEFAULT_STACK_SIZE to System.Threading.DefaultStackSize Mar 11, 2026
…behavior

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review March 11, 2026 01:20
Copilot AI review requested due to automatic review settings March 11, 2026 01:20
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Mar 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the IIS in-process handler from the deprecated DEFAULT_STACK_SIZE runtime config to System.Threading.DefaultStackSize, converting configured hex stack-size values into the decimal string required by the new runtime property.

Changes:

  • Updated the runtime property name used for stack-size configuration.
  • Updated in-process options parsing to convert hex stack-size strings to decimal and adjusted the default to a decimal value.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxr.h Switches stack-size host property name to System.Threading.DefaultStackSize.
src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/InProcessOptions.cpp Converts configured stack size from hex to decimal string; updates default to decimal.

You can also share your feedback on Copilot code review. Take the survey.

@gfoidl gfoidl added feature-iis Includes: IIS, ANCM area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Mar 11, 2026
@MichalStrehovsky MichalStrehovsky merged commit a200b84 into main Mar 16, 2026
29 checks passed
@MichalStrehovsky MichalStrehovsky deleted the copilot/update-default-stack-size branch March 16, 2026 03:21
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview3 milestone Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-iis Includes: IIS, ANCM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants