-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Description
In the process of migrating a huge Enterprise solution to .NET8, we encountered an unexpected regression:
The default stack size for the main and secondary threads has been reduced from 4 MB
(x64) to 1.5 MB
.
This resulted in a StackOverflowException
in a RestAPI service using AutoMapper
, custom serialization logic, and building dynamic methods.
The DefaultStackSize
environment variable is internal and cannot be configured from an external .json config file.
RETAIL_CONFIG_DWORD_INFO(INTERNAL_DefaultStackSize, W("DefaultStackSize"), 0, "Stack size to use for new VM threads when thread is created with default stack size (dwStackSize == 0).")
Configuration
- .NET 8 (SDK 8.0.100)
- Windows 10 and Ubuntu 22 (64-bit)
- x64 and AnyCPU (
Prefer 32-bit
is disabled)
Regression?
Yes, this is regression from .NET Framework where the default stack size was 4 MB for 64-bit applications.
I expect 4 MB and this to work the same for the .NET Framework and .NET8+ on any OS, when building for x64 and AnyCPU platforms.
Data
// This line of code will fail if you try to run .NET8 (AnyCPU/x64) application but will work for .NET Framework (x64)
var numbers = stackalloc byte[2 * 1024 * 1024];
Analysis
An article about internals of threads:
https://learn.microsoft.com/en-us/archive/blogs/markrussinovich/pushing-the-limits-of-windows-processes-and-threads