Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
lib: setup IPC channel before console
Browse files Browse the repository at this point in the history
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: nodejs/node#16562
Fixes: nodejs/node#16141
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
seishun authored and Qard committed Nov 2, 2017
1 parent d1dbd95 commit 55fa471
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-child-process-stdout-ipc.js
Original file line number Diff line number Diff line change
@@ -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);
}));

0 comments on commit 55fa471

Please sign in to comment.