Skip to content

Commit

Permalink
child_process: fix stdio sockets creation
Browse files Browse the repository at this point in the history
`readable` and `writable` properties can be passed directly to the
`net.Socket` constructor. This change also avoids an unnecessary call
to `read(0)` on the `stdin` socket. This behavior was disclosed when
trying to merge `libuv@1.19.0` and specifically this commit:
libuv/libuv@fd04939.

PR-URL: #18701
Refs: libuv/libuv#1655
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
santigimeno authored and BridgeAR committed Feb 16, 2018
1 parent f25104e commit b74a6da
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
12 changes: 1 addition & 11 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,7 @@ function flushStdio(subprocess) {


function createSocket(pipe, readable) {
var s = new net.Socket({ handle: pipe });

if (readable) {
s.writable = false;
s.readable = true;
} else {
s.writable = true;
s.readable = false;
}

return s;
return net.Socket({ handle: pipe, readable, writable: !readable });
}


Expand Down
2 changes: 1 addition & 1 deletion test/async-hooks/test-pipewrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function onexit() {
// Usually it is just one event, but it can be more.
assert.ok(ioEvents >= 3, `at least 3 stdout io events, got ${ioEvents}`);

checkInvocations(pipe1, { init: 1, before: 2, after: 2 },
checkInvocations(pipe1, { init: 1, before: 1, after: 1 },
'pipe wrap when sleep.spawn was called');
checkInvocations(pipe2, { init: 1, before: ioEvents, after: ioEvents },
'pipe wrap when sleep.spawn was called');
Expand Down

0 comments on commit b74a6da

Please sign in to comment.