ELECTRON_RUN_AS_NODE is not correctly set for forked child process
stevebaxter opened this issue · 2 comments
The Electron version of Node includes code to set ELECTRON_RUN_AS_NODE=1
in the environment of child process. This is the relevant commit:
The problem comes if the caller passes in process.env
as an option to child_process.fork(), this seems to be quite a common thing to do (worker-farm does this for instance). As an example, something like this:
child_process.fork("myscript.js", [], { env: process.env });
In this case, this line tries to change the actual process.env, not a copy:
f263751#diff-1dea15b19e826b37828eef6c41166ffeR57
The result is that ELECTRON_RUN_AS_NODE
is set to "1"
rather than 1
as process.env will implicitly convert all values to strings (see https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_env). This stops the child process running as node, and weird things can happen. In particular, the debug tools may stop working. More descriptions of these symptoms are available here:
I suspect the solution will be to ensure we modify a copy of the environment we have been passed, for instance changing:
// When forking a child script, we setup a special environment to make
// the atom-shell binary run like the upstream node.
if (!options.env) {
options.env = Object.create(process.env);
}
options.env.ELECTRON_RUN_AS_NODE = 1;
to something like:
// When forking a child script, we setup a special environment to make
// the atom-shell binary run like the upstream node.
if (options.env) {
options.env = Object.create(options.env);
} else {
options.env = Object.create(process.env);
}
options.env.ELECTRON_RUN_AS_NODE = 1;
As a workaround, callers can explicitly pass a copy of process.env
(worker-farm supports this for instance).
This repository is not used any more and all node patches live in electron/electron
can you raise this over there.
Done, electron/electron#19738