Skip to content

Conversation

seishun
Copy link
Contributor

@seishun seishun commented Oct 27, 2017

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.

Fixes: #16141

Will add a test if there are no objections to this approach.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

lib

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Oct 27, 2017
Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no way to write a test for this, can you add a comment so that nobody accidentally moves this around again?

@refack
Copy link
Contributor

refack commented Oct 27, 2017

AFAICT a regression test is simple:

d:\code\node-master$ set NODE_CHANNEL_FD=0

d:\code\node-master$ node
child_process.js:107
  p.open(fd);
    ^

Error: EINVAL: invalid argument, uv_pipe_open
    at Object.exports._forkChild (child_process.js:107:5)
    at Object.setupChannel (internal/process.js:244:8)
    at startup (bootstrap_node.js:69:16)
    at bootstrap_node.js:608:3

d:\code\node-master$ set NODE_CHANNEL_FD=

d:\code\node-master$

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but a test would be great.

@seishun
Copy link
Contributor Author

seishun commented Oct 28, 2017

Added a test. @cjihrig @addaleax @refack PTAL

}

const proc = spawn(process.execPath, [__filename, 'child'], {
stdio: ['inherit', 'ipc', 'inherit']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

// make sure `fd[1]` has not been opened for `console`

@@ -74,6 +68,12 @@

_process.setupRawDebug();

const browserGlobals = !process._noBrowserGlobals;
if (browserGlobals) {
setupGlobalTimeouts();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

// This needs to happen after `_process.setupChannel()`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a regression test and git blame, so I don't think it's necessary (or even useful in this form tbh).

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM FWIW

@seishun
Copy link
Contributor Author

seishun commented Oct 29, 2017

@cjihrig
Copy link
Contributor

cjihrig commented Oct 29, 2017

Still LGTM, thanks.

@seishun
Copy link
Contributor Author

seishun commented Oct 29, 2017

The failure seems unrelated.

seishun added a commit that referenced this pull request Oct 29, 2017
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: #16562
Fixes: #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]>
@seishun seishun closed this Oct 29, 2017
@seishun
Copy link
Contributor Author

seishun commented Oct 29, 2017

Landed in 403ccb6.

@seishun seishun deleted the ipc-einval branch October 29, 2017 19:29
gibfahn pushed a commit that referenced this pull request Oct 30, 2017
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: #16562
Fixes: #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]>
gibfahn pushed a commit that referenced this pull request Oct 30, 2017
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: #16562
Fixes: #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]>
gibfahn pushed a commit that referenced this pull request Oct 31, 2017
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: #16562
Fixes: #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]>
@gibfahn gibfahn mentioned this pull request Oct 31, 2017
Qard pushed a commit to ayojs/ayo that referenced this pull request Nov 2, 2017
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]>
Qard pushed a commit to ayojs/ayo that referenced this pull request Nov 2, 2017
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]>
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

@seishun
Copy link
Contributor Author

seishun commented Nov 16, 2017

No need to backport since #16141 isn't an issue on v6.x AFAIK.

addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error "write EINVAL"
8 participants