Skip to content

worker: respect resourceLimits when --max-old-space-size is set - #67544

Open
rudolf wants to merge 2 commits into
nodejs:mainfrom
rudolf:fix/worker-resource-limits-max-old-space-size
Open

rudolf wants to merge 2 commits into
nodejs:mainfrom
rudolf:fix/worker-resource-limits-max-old-space-size

Conversation

@rudolf

@rudolf rudolf commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Currently, --max-old-space-size (and --max-old-space-size-percentage) sets V8's process-global v8_flags.max_old_space_size, which Heap::ConfigureHeap applies after per-isolate v8::ResourceConstraints. As a result, setting --max-old-space-size for the main process silently overrides resourceLimits.maxOldGenerationSizeMb on every Worker thread.

This PR handles --max-old-space-size in PerIsolateOptions and applies it to isolates via v8::ResourceConstraints::set_max_old_generation_size_in_bytes() instead of the global v8_flags override (unless --max-heap-size is also passed, which requires V8's flag handling for young-generation derivation).

  • Workers without resourceLimits.maxOldGenerationSizeMb continue to inherit the parent isolate's --max-old-space-size limit, and worker.resourceLimits.maxOldGenerationSizeMb now accurately reports that inherited limit.
  • Workers configured with an explicit resourceLimits.maxOldGenerationSizeMb or worker execArgv have their per-worker limit respected.

We need to decide if this behavior change is a bug fix or needs a semver major.

Fixes: #67014
Refs: #43991
Assisted-by: a closed-source coding agent

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. config Issues and PRs related to Node.js configuration and feature settings. needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API. labels Nov 17, 2026
@rudolf
rudolf force-pushed the fix/worker-resource-limits-max-old-space-size branch from fba3a0e to fbfc7f1 Compare November 17, 2026 14:40
Handle --max-old-space-size in PerIsolateOptions and apply it via
v8::ResourceConstraints::set_max_old_generation_size_in_bytes()
instead of setting the process-global v8_flags.max_old_space_size
flag (unless --max-heap-size is also passed).

Workers without an explicit resourceLimits.maxOldGenerationSizeMb
continue to inherit the parent isolate's --max-old-space-size (and
report that inherited limit on worker.resourceLimits), while workers
with an explicit resourceLimits.maxOldGenerationSizeMb or worker
execArgv can override it.

Fixes: nodejs#67014
Refs: nodejs#43991
Signed-off-by: Rudolf Meijering <skaapgif@gmail.com>
@rudolf
rudolf force-pushed the fix/worker-resource-limits-max-old-space-size branch from fbfc7f1 to aa6c656 Compare November 17, 2026 15:13
@rudolf
rudolf marked this pull request as ready for review November 17, 2026 15:14
Signed-off-by: Rudolf Meijering <skaapgif@gmail.com>
@ronag
ronag requested review from jasnell and joyeecheung November 17, 2026 16:44
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.66%. Comparing base (3db9632) to head (11ae8f9).
⚠️ Report is 85 commits behind head on main.

Files with missing lines Patch % Lines
src/node.cc 53.84% 3 Missing and 3 partials ⚠️
src/node_options.cc 70.58% 4 Missing and 1 partial ⚠️
src/api/environment.cc 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67544      +/-   ##
==========================================
- Coverage   90.67%   90.66%   -0.01%     
==========================================
  Files         800      800              
  Lines      281081   281129      +48     
  Branches    54314    54314              
==========================================
+ Hits       254870   254890      +20     
- Misses      16312    16322      +10     
- Partials     9899     9917      +18     
Files with missing lines Coverage Δ
src/api/embed_helpers.cc 76.77% <100.00%> (+0.33%) ⬆️
src/node_internals.h 82.25% <ø> (ø)
src/node_options.h 95.78% <100.00%> (+0.01%) ⬆️
src/node_worker.cc 81.78% <100.00%> (+0.24%) ⬆️
src/api/environment.cc 79.85% <92.85%> (-0.12%) ⬇️
src/node_options.cc 87.99% <70.58%> (-0.25%) ⬇️
src/node.cc 78.41% <53.84%> (-0.76%) ⬇️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell
jasnell requested a review from addaleax November 18, 2026 13:01
@araujogui araujogui added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. config Issues and PRs related to Node.js configuration and feature settings. needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

worker_threads: resourceLimits memory settings overridden by process flags

4 participants