process: move child process IPC setup condition into node.js
Instead of branching in main_thread_only.js, move the branch on process.env.NODE_CHANNEL_FD in node.js so it's easier to tell when this needs to happen. Also added comments about what side effect this causes, and lazy load `assert`. PR-URL: https://github.com/nodejs/node/pull/25130 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
55a1889af7
commit
0c1a388218
@ -155,7 +155,12 @@ function startup() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMainThread) {
|
// If the process is spawned with env NODE_CHANNEL_FD, it's probably
|
||||||
|
// spawned by our child_process module, then initialize IPC.
|
||||||
|
// This attaches some internal event listeners and creates:
|
||||||
|
// process.send(), process.channel, process.connected,
|
||||||
|
// process.disconnect()
|
||||||
|
if (isMainThread && process.env.NODE_CHANNEL_FD) {
|
||||||
mainThreadSetup.setupChildProcessIpcChannel();
|
mainThreadSetup.setupChildProcessIpcChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@ const {
|
|||||||
getMainThreadStdio
|
getMainThreadStdio
|
||||||
} = require('internal/process/stdio');
|
} = require('internal/process/stdio');
|
||||||
|
|
||||||
const assert = require('assert').strict;
|
|
||||||
|
|
||||||
function setupStdio() {
|
function setupStdio() {
|
||||||
setupProcessStdio(getMainThreadStdio());
|
setupProcessStdio(getMainThreadStdio());
|
||||||
}
|
}
|
||||||
@ -163,9 +161,8 @@ function setupSignalHandlers(internalBinding) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupChildProcessIpcChannel() {
|
function setupChildProcessIpcChannel() {
|
||||||
// If we were spawned with env NODE_CHANNEL_FD then load that up and
|
const assert = require('assert').strict;
|
||||||
// start parsing data from that stream.
|
|
||||||
if (process.env.NODE_CHANNEL_FD) {
|
|
||||||
const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
|
const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
|
|
||||||
@ -174,7 +171,6 @@ function setupChildProcessIpcChannel() {
|
|||||||
|
|
||||||
require('child_process')._forkChild(fd);
|
require('child_process')._forkChild(fd);
|
||||||
assert(process.send);
|
assert(process.send);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user