Skip to content

Add the Worker env option and SHARE_ENV - #1415

Open
ctate wants to merge 5 commits into
mainfrom
ctate/add-worker-env-de9a20
Open

ctate wants to merge 5 commits into
mainfrom
ctate/add-worker-env-de9a20

Conversation

@ctate

@ctate ctate commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator
  • new Worker(file, { env }) accepts an object or SHARE_ENV and builds the worker's process.env as Node does, including Node's validation and its omission of array-index names.
  • Child processes that a worker spawns inherit the worker's process.env.
  • Programs without a SHARE_ENV worker take no environment lock; corpus 5998-5999 match Node v24.22.0.

new Worker(filename, { env }) builds the worker's process.env as Node's
constructor does. undefined or null copies the parent's environment, as
before. An object gives the worker its own enumerable string-keyed
properties, each converted with String(); names that are array indices
are left out, as in Node. SHARE_ENV (the symbol registered as
nodejs.worker_threads.SHARE_ENV) has the worker and its parent use the
process environment. Any other value throws ERR_INVALID_ARG_TYPE. The
option is checked after argv and before name. SHARE_ENV from a worker
that has its own copy of the environment is refused.

After the first SHARE_ENV worker starts, process.env reads, writes,
deletes and enumeration of the process environment hold a lock on POSIX
hosts. Programs without such a worker take no lock.

Child processes spawned in a worker without an env option now inherit
the worker's process.env, as Node passes process.env. Before, they
inherited the process environment.

The worker unit recognizes SHARE_ENV through scr_dyn_symbol_key_fn,
which the symbol unit installs when its registry first holds a symbol.
Programs without symbols do not link the symbol unit.

Corpus 5998-5999 match Node v24.22.0.
@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 20, 2026 5:10pm UTC

scr_arr_release(inherited);
pid_t pid = -1;
int spawn_err = posix_spawnp(&pid, cmd->data, &fa, NULL, argv, environ);
int spawn_err = posix_spawnp(&pid, cmd->data, &fa, NULL, argv, envp != NULL ? envp : environ);

@vercel vercel Bot Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On POSIX, a worker with a different env.PATH still resolves spawned executables against the main thread's PATH, causing ENOENT for worker-only commands or running the wrong executable.

Fix on Vercel

scr_worker.h is compiled without SCR_WORKERS (the runtime's
common-symbols check), where scr_core.h does not declare the
ScrContextEnv typedef. scr_worker_thread_start's environment parameter
now uses struct ScrContextEnv, the same type.

This branch was successfully deployed

1 active deployment
Preview — c3b7446f Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant