From e9ee7e44bef0b88469df1bded272593f02d5b63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 2 Jul 2022 18:38:11 +0200 Subject: [PATCH] build,test: increase stack size limit on Windows Fixes: https://github.com/nodejs/node/issues/43630 PR-URL: https://github.com/nodejs/node/pull/43632 Reviewed-By: Ben Noordhuis Reviewed-By: Jiawen Geng --- node.gyp | 6 ++++++ test/parallel/test-stack-size-limit.js | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/parallel/test-stack-size-limit.js diff --git a/node.gyp b/node.gyp index 340ffc27ade9f7..6b3a6d991dd376 100644 --- a/node.gyp +++ b/node.gyp @@ -172,6 +172,12 @@ 'RandomizedBaseAddress': 2, # enable ASLR 'DataExecutionPrevention': 2, # enable DEP 'AllowIsolation': 'true', + # By default, the MSVC linker only reserves 1 MiB of stack memory for + # each thread, whereas other platforms typically allow much larger + # stack memory sections. We raise the limit to make it more consistent + # across platforms and to support the few use cases that require large + # amounts of stack memory, without having to modify the node binary. + 'StackReserveSize': 0x800000, }, }, diff --git a/test/parallel/test-stack-size-limit.js b/test/parallel/test-stack-size-limit.js new file mode 100644 index 00000000000000..f66fe8527c8c5d --- /dev/null +++ b/test/parallel/test-stack-size-limit.js @@ -0,0 +1,26 @@ +'use strict'; + +require('../common'); + +const assert = require('assert'); +const { spawnSync } = require('child_process'); + +// The default --stack-size is 984, which is below Windows' default stack size +// limit of 1 MiB. However, even a slight increase would cause node to exceed +// the 1 MiB limit and thus to crash with the exit code STATUS_STACK_OVERFLOW. +// Newer versions of Node.js allow the stack size to grow to up to 8 MiB, which +// better aligns with default limits on other platforms and which is commonly +// used for browsers on Windows. +// See https://github.com/nodejs/node/issues/43630. + +const { status, signal, stderr } = spawnSync(process.execPath, [ + '--stack-size=2000', + '-e', + '(function explode() { return explode(); })()', +], { + encoding: 'utf8' +}); + +assert.strictEqual(status, 1); +assert.strictEqual(signal, null); +assert.match(stderr, /Maximum call stack size exceeded/);