diff options
author | Nikolai Vavilov <vvnicholas@gmail.com> | 2017-10-27 21:23:59 +0300 |
---|---|---|
committer | Gibson Fahnestock <gibfahn@gmail.com> | 2017-10-31 00:15:10 +0000 |
commit | 8c0c456c73a25605122676341ff3f751cbf74543 (patch) | |
tree | aaed3b0e164c902101c58f6beae045d48aba5331 | |
parent | 3d8a7e97feaf3b68fb3ab67f9247f77b4dda4e83 (diff) | |
download | node-new-8c0c456c73a25605122676341ff3f751cbf74543.tar.gz |
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 <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r-- | lib/internal/bootstrap_node.js | 12 | ||||
-rw-r--r-- | test/parallel/test-child-process-stdout-ipc.js | 18 |
2 files changed, 24 insertions, 6 deletions
diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 4a941b5385..1f202d2335 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -33,12 +33,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, @@ -70,6 +64,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); +})); |