From 55fa471ec562edd499ea74f0406cc3eb134079a6 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Fri, 27 Oct 2017 21:23:59 +0300 Subject: [PATCH] lib: setup IPC channel before console Initializing IOCP on the same fd twice can fail on Windows. Consequently, if the IPC channel uses fd 1 or 2 and the console is setup first, writing to the IPC channel will fail. PR-URL: https://github.com/nodejs/node/pull/16562 Fixes: https://github.com/nodejs/node/issues/16141 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- lib/internal/bootstrap_node.js | 12 ++++++------ test/parallel/test-child-process-stdout-ipc.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 test/parallel/test-child-process-stdout-ipc.js diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 868a984e56..ad0b3612c3 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -40,12 +40,6 @@ NativeModule.require('internal/process/next_tick').setup(); NativeModule.require('internal/process/stdio').setup(); - const browserGlobals = !process._noBrowserGlobals; - if (browserGlobals) { - setupGlobalTimeouts(); - setupGlobalConsole(); - } - const perf = process.binding('performance'); const { NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE, @@ -77,6 +71,12 @@ _process.setupRawDebug(); + const browserGlobals = !process._noBrowserGlobals; + if (browserGlobals) { + setupGlobalTimeouts(); + setupGlobalConsole(); + } + // Ensure setURLConstructor() is called before the native // URL::ToObject() method is used. NativeModule.require('internal/url'); diff --git a/test/parallel/test-child-process-stdout-ipc.js b/test/parallel/test-child-process-stdout-ipc.js new file mode 100644 index 0000000000..c916be95b7 --- /dev/null +++ b/test/parallel/test-child-process-stdout-ipc.js @@ -0,0 +1,18 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); + +const spawn = require('child_process').spawn; + +if (process.argv[2] === 'child') { + process.send('hahah'); + return; +} + +const proc = spawn(process.execPath, [__filename, 'child'], { + stdio: ['inherit', 'ipc', 'inherit'] +}); + +proc.on('exit', common.mustCall(function(code) { + assert.strictEqual(code, 0); +}));