Repository navigation
Increase thread stack size limit on Windows #43630
Copy link
Copy link
Closed
Labels
addonsIssues and PRs related to native addons.Issues and PRs related to native addons.buildIssues and PRs related to Node.js builds or CI infrastructure.Issues and PRs related to Node.js builds or CI infrastructure.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
Description
Activity
- addedwindowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.buildIssues and PRs related to Node.js builds or CI infrastructure.Issues and PRs related to Node.js builds or CI infrastructure.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.addonsIssues and PRs related to native addons.Issues and PRs related to native addons.
on Jun 30, 2022 cc @nodejs/build-files @nodejs/platform-windows
Can you please point to where it is hard-coded in the repo?
@targos I think the MSVC linker always embeds a hard-coded value and we just don't override the default of 1 MiB.
After looking into this more, it seems like it's as simple as adding
'StackReserveSize': 0x800000toVCLinkerToolinmsvs_settings. I am waiting for my local build to complete so I can confirm.- added a commit that references this issue
on Jul 2, 2022 - added a commit that references this issue
on Jul 12, 2022 - added a commit that references this issue
on Jul 20, 2022 - added a commit that references this issue
on Jul 31, 2022 - added a commit that references this issue
on Oct 10, 2022 - added a commit that references this issue
on Apr 8, 2026
Metadata
Metadata
Assignees
Labels
addonsIssues and PRs related to native addons.Issues and PRs related to native addons.buildIssues and PRs related to Node.js builds or CI infrastructure.Issues and PRs related to Node.js builds or CI infrastructure.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
What is the problem this feature will solve?
Node.js uses a hard-coded default stack size limit on Windows, which is 1 MiB:
On other platforms, the limit is usually around 8 or 10 MiB and can be changed using
ulimit -s.V8 stack size
The default V8 stack size limit on 64-bit systems is 984 kBytes, which is below the thread stack size limit on all supported operating systems. On Linux, the V8 stack size can usually be increased almost arbitrarily by passing
--stack-size=...if needed, and the maximum thread stack size can usually be changed without modifying thenodeexecutable (ulimit -s). On Windows, however, raising V8's stack size beyond the hard-coded thread stack size limit of 1 MiB will crash the process:Raising the hard-coded thread stack size limit will allow greater manual adjustments through
--stack-size=...beyond the default value.Native addons
Native addons are not necessarily limited by the V8 stack size limit, but they are limited by the hard-coded thread stack size limit (unless they create new threads or fibers). While the stack size limit of 1 MiB is often sufficient, some libraries perform stack allocations exceeding the limit. Such libraries work just fine when using Node.js on Linux but overflow the stack on Windows.
Raising the hard-coded thread stack size limit will simplify creating portable native addons that rely on large stack allocations (however questionable large stack allocations might be).
What is the feature you are proposing to solve the problem?
Increase the thread stack size limit beyond the default value of 1 MiB. See
/STACK.Only increase the reserve size, not the commit size, to avoid an increase in the actual memory usage.
For comparison, Chrome, Edge, and Firefox all use a hard-coded thread stack size limit of 8 MiB.
What alternatives have you considered?
node-mceliece-nistandnode-pqcleanswitch to a WebAssembly module instead of a native addon on Windows, to support cryptographic implementations that rely on large stack allocations (which are mapped to heap memory in WebAssembly).editbin.execan be used to change the hard-coded stack size ofnode.exe: