Skip to content

[v24.x backport] child_process: inherit a reassigned process.env - #67921

Closed
everett1992 wants to merge 1 commit into
nodejs:v24.x-stagingfrom
everett1992:backport-66883-to-v24.x
Closed

everett1992 wants to merge 1 commit into
nodejs:v24.x-stagingfrom
everett1992:backport-66883-to-v24.x

Conversation

@everett1992

Copy link
Copy Markdown
Contributor

Backport of #66883 to v24.x.

v24.23.0 includes the bug from #65325 (da67ac7) but not its fix, so v24 now has the regression from #66882: a child spawned without options.env ignores a reassigned process.env.
The repro from #66882 prints set on v24.22.3 and undefined on v24.23.0.

The commit cherry-picks cleanly onto v24.x-staging, and its message is unchanged.

make -j64 test passes on Linux x64 (gcc 14): 5879 JS tests and 260 cctests, no failures.

Refs: #66883
Refs: #66882

Since v26.11.0, spawning without options.env builds the child's
environment from the OS environment block. Code that replaces
process.env, e.g. process.env = { ...process.env, FOO: 'x' }, had its
changes silently dropped. The child_process docs give process.env as
the default for options.env, and { env: process.env } still saw the
replacement object, so the two disagreed.

Make getEnvPairs() take the object to read and return undefined unless
it is still the native env proxy. When it isn't, copy process.env as
before. A plain object is copied without going through the env
interceptors, so that path stays cheap.

Assisted-by: a closed-source coding agent
Signed-off-by: Caleb ツ Everett <calebev@amazon.com>
PR-URL: nodejs#66883
Fixes: nodejs#66882
Refs: nodejs#65325
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. v24.x Issues that can be reproduced on v24.x or PRs targeting the v24.x-staging branch. labels Dec 1, 2026
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.42%. Comparing base (9e39360) to head (b819544).
⚠️ Report is 966 commits behind head on v24.x-staging.

Files with missing lines Patch % Lines
src/process_wrap.cc 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           v24.x-staging   #67921      +/-   ##
=================================================
+ Coverage          90.31%   90.42%   +0.11%     
=================================================
  Files                711      717       +6     
  Lines             228425   241949   +13524     
  Branches           43160    46207    +3047     
=================================================
+ Hits              206293   218785   +12492     
- Misses             14090    14611     +521     
- Partials            8042     8553     +511     
Files with missing lines Coverage Δ
lib/child_process.js 92.48% <100.00%> (-1.65%) ⬇️
src/process_wrap.cc 75.65% <75.00%> (+0.18%) ⬆️

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

@Renegade334 Renegade334 closed this Dec 1, 2026
@Renegade334

Copy link
Copy Markdown
Member

These are only needed for PRs that don't land cleanly.

@everett1992

Copy link
Copy Markdown
Contributor Author

@Renegade334 Any ETA to land the fix on v24 then? I was pretty surprised to see the bug backported without it's fix.
The breaking change in v26 didn't have much impact to me, because we're still largely on v24, but now a lot is broken.

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++. child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. v24.x Issues that can be reproduced on v24.x or PRs targeting the v24.x-staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants