Repository navigation
worker_threads resource limits option not working with cluster module #41066
Description
Activity
- addedclusterIssues and PRs related to the cluster subsystem.Issues and PRs related to the cluster subsystem.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
on Dec 3, 2021 The primary process above runs with no
NODE_OPTIONS, so that theresourceLimits.maxOldGenerationSizeMbseems to work.A similar case can be observed without cluster module if
--max-old-space-sizeis given inNODE_OPTIONS.// test.js const { Worker, isMainThread } = require('worker_threads'); const v8 = require('v8'); if (isMainThread) { new Worker(__filename, { resourceLimits: { maxOldGenerationSizeMb: 200 } }); } const type = isMainThread ? 'main' : 'work'; console.log(`[${type}] limit: ${v8.getHeapStatistics().heap_size_limit}`);
Output
> node test-worker.js [main] limit: 4345298944 [work] limit: 260046848 > NODE_OPTIONS=--max-old-space-size=512 node test.js [main] limit: 587202560 [work] limit: 587202560
When
max_old_space_sizeis concurrently given from bothNODE_OPTIONSand the constructor option, the one fromNODE_OPTIONSseems to have more priority.Lines 5201 to 5207 in e64613d
if (constraints.max_old_generation_size_in_bytes() > 0) { max_old_generation_size = constraints.max_old_generation_size_in_bytes(); } if (FLAG_max_old_space_size > 0) { max_old_generation_size = static_cast<size_t>(FLAG_max_old_space_size) * MB; } else if (FLAG_max_heap_size > 0) { github-actions commented
on Jun 25, 2026 on Jun 25, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jun 25, 2026 github-actions commented
on Jul 26, 2026 on Jul 26, 2026 – with GitHub ActionsContributorMore actionsThis issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Version
v17.2.0
Platform
20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
Subsystem
worker_threads
What steps will reproduce the bug?
index.mjs
worker.mjs
output:
How often does it reproduce? Is there a required condition?
Whenever I use
worker_threadsmodule with acluster- worker resourceLimits option is ignored.What is the expected behavior?
Expected output:
What do you see instead?
Max old space heap size probably was inherited from parent process (cluster) and resource limits option was ignored.
Additional information
This behavior may cause the memory leak on the worker to be handled incorrectly. Worker process will be killed if old heap space reach cluster process limits, not options I've passed.