Repository navigation
child_process: inherit a reassigned process.env - #66883
Conversation
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>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66883 +/- ##
==========================================
+ Coverage 90.50% 90.51% +0.01%
==========================================
Files 797 797
Lines 278268 278369 +101
Branches 53468 53482 +14
==========================================
+ Hits 251838 251963 +125
+ Misses 16813 16765 -48
- Partials 9617 9641 +24
🚀 New features to boost your workflow:
|
|
@nodejs/child_process @codebytere @@aduh95 @jasnell — this fixes #66882, a regression from #65325 where a reassigned process.env is no longer inherited by children. It keeps the fast path for the common case. |
|
CI is green (node-test-pull-request/78765) and this has two approvals. Could someone add commit-queue? @addaleax |
|
Landed in 2aef805 |
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: #66883
Fixes: #66882
Refs: #65325
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
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: #66883
Fixes: #66882
Refs: #65325
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
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: #66883
Fixes: #66882
Refs: #65325
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Extend Arch's prepare() instead of redefining it, preserving the OpenSSL 4.x test and child-process environment backports. The duplicate function silently discarded both, leaving test-x509-escaping expecting 'good.example.com' where OpenSSL 4.1 returns undefined. https://gitlab.archlinux.org/archlinux/packaging/packages/nodejs/-/blob/26.13.1-1/PKGBUILD nodejs/node#66775 nodejs/node#66883 https://archriscv.felixc.at/.status/logs/nodejs/nodejs-26.13.1-1.log
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>
There's no firm date for the next v24.x release, but they're usually ~monthly for LTS lines. |
|
Why was the breaking change allowed to be backported without backporting this fix? Did I miss a tag or process to prevent that? |
Since #65325 (first released in v26.11.0), spawning a child without
options.envbuilds its environment from the OS environment block. If user code has reassignedprocess.env(process.env = { ...process.env, FOO: 'x' }), the child no longer sees the change, even though{ env: process.env }still does. With--permissionthe old path is taken, which hides the bug. See #66882 for the repro and impact.This keeps the fast path for the common case and only takes it while
process.envis still the native env proxy.getEnvPairs()now takes the object and returnsundefinedunlessenv_proxy_ctor_template()->HasInstance()is true. That is the same checknode_messaging.ccuses to recognizeprocess.envwhen cloning it. The check is native becausechild_processcan be loaded afterprocess.envhas been reassigned, so comparing against a reference captured in JS wouldn't work. OtherwisenormalizeSpawnArguments()falls back to the copy path used before #65325. Spreading a plain object doesn't go through the interceptors, so that path is cheap there.test/parallel/test-child-process-env-reassigned.jscoversspawn,spawnSync,exec,execSync,execFile,execFileSync,fork, PATH lookup (non-Windows), parity with{ env: process.env }, and assigning the original object back. It fails on v26.12.0 and passes on v26.10.0 and with this change.Since this is a v26.11.0 regression, it would be good to land it before v26 goes LTS on 2026-10-28.
Fixes: #66882
Refs: #65325
I used Claude Code to write the patch, the test and this description. I reviewed the change and ran the new and existing child_process tests locally.