Skip to content

Commit daadd58

Browse files
tniessentargos
authored andcommittedJul 31, 2022
build,test: increase stack size limit on Windows
Fixes: #43630 PR-URL: #43632 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent 4d8daae commit daadd58

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

‎node.gyp

+6
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@
173173
'RandomizedBaseAddress': 2, # enable ASLR
174174
'DataExecutionPrevention': 2, # enable DEP
175175
'AllowIsolation': 'true',
176+
# By default, the MSVC linker only reserves 1 MiB of stack memory for
177+
# each thread, whereas other platforms typically allow much larger
178+
# stack memory sections. We raise the limit to make it more consistent
179+
# across platforms and to support the few use cases that require large
180+
# amounts of stack memory, without having to modify the node binary.
181+
'StackReserveSize': 0x800000,
176182
},
177183
},
178184

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const { spawnSync } = require('child_process');
7+
8+
// The default --stack-size is 984, which is below Windows' default stack size
9+
// limit of 1 MiB. However, even a slight increase would cause node to exceed
10+
// the 1 MiB limit and thus to crash with the exit code STATUS_STACK_OVERFLOW.
11+
// Newer versions of Node.js allow the stack size to grow to up to 8 MiB, which
12+
// better aligns with default limits on other platforms and which is commonly
13+
// used for browsers on Windows.
14+
// See https://github.com/nodejs/node/issues/43630.
15+
16+
const { status, signal, stderr } = spawnSync(process.execPath, [
17+
'--stack-size=2000',
18+
'-e',
19+
'(function explode() { return explode(); })()',
20+
], {
21+
encoding: 'utf8'
22+
});
23+
24+
assert.strictEqual(status, 1);
25+
assert.strictEqual(signal, null);
26+
assert.match(stderr, /Maximum call stack size exceeded/);

0 commit comments

Comments
 (0)
Please sign in to comment.