Skip to content

worker: parse NODE_OPTIONS when env option is not provided#62306

Open
semimikoh wants to merge 2 commits intonodejs:mainfrom
semimikoh:fix/worker-node-options-env
Open

worker: parse NODE_OPTIONS when env option is not provided#62306
semimikoh wants to merge 2 commits intonodejs:mainfrom
semimikoh:fix/worker-node-options-env

Conversation

@semimikoh
Copy link
Copy Markdown
Contributor

When env option is not explicitly provided to new Worker(),
runtime changes to process.env.NODE_OPTIONS (e.g. adding --import)
are not picked up by the worker thread.

This happens because in node_worker.cc, the NODE_OPTIONS parsing
block is gated behind args[1]->IsObject() || args[2]->IsArray().
When env is not provided, args[1] is null (cloned from
process.env), so the condition is false and NODE_OPTIONS parsing
is skipped entirely.

This fix adds args[1]->IsNull() to the condition so that
NODE_OPTIONS is also parsed when the env is inherited (cloned)
from the parent process.

Fixes: #62301

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support. labels Mar 18, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (4d2d6de) to head (91566fb).
⚠️ Report is 390 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62306      +/-   ##
==========================================
- Coverage   89.66%   89.65%   -0.01%     
==========================================
  Files         676      708      +32     
  Lines      206575   220413   +13838     
  Branches    39555    42274    +2719     
==========================================
+ Hits       185225   197612   +12387     
- Misses      13501    14672    +1171     
- Partials     7849     8129     +280     
Files with missing lines Coverage Δ
src/node_worker.cc 82.32% <ø> (+0.91%) ⬆️

... and 226 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.

@mertcanaltin
Copy link
Copy Markdown
Member

Thank you, could you add a test for this?

@semimikoh
Copy link
Copy Markdown
Contributor Author

@mertcanaltin

Added a test in 9f345a9. It verifies that NODE_OPTIONS set at runtime are picked up by a worker when the env option is not provided.

Copy link
Copy Markdown
Member

@mertcanaltin mertcanaltin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@semimikoh semimikoh force-pushed the fix/worker-node-options-env branch from 9f345a9 to 795ebcc Compare April 30, 2026 18:04
semimikoh added 2 commits May 1, 2026 03:34
Signed-off-by: semimikoh <ejffjeosms@gmail.com>
Signed-off-by: semimikoh <ejffjeosms@gmail.com>
@semimikoh semimikoh force-pushed the fix/worker-node-options-env branch from 795ebcc to 91566fb Compare April 30, 2026 18:34
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++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:worker_threads does not load --import file.js unless explicitly setting env option

3 participants