Skip to content

Commit 91f2cf9

Browse files
santigimenoMylesBorins
authored andcommitted
child_process: fix stdio sockets creation
`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 `[email protected]` and specifically this commit: libuv/libuv@fd04939. PR-URL: #18701 Refs: libuv/libuv#1655 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 0fc33fb commit 91f2cf9

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

lib/internal/child_process.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,7 @@ function flushStdio(subprocess) {
238238

239239

240240
function createSocket(pipe, readable) {
241-
var s = new net.Socket({ handle: pipe });
242-
243-
if (readable) {
244-
s.writable = false;
245-
s.readable = true;
246-
} else {
247-
s.writable = true;
248-
s.readable = false;
249-
}
250-
251-
return s;
241+
return net.Socket({ handle: pipe, readable, writable: !readable });
252242
}
253243

254244

test/async-hooks/test-pipewrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function onexit() {
7878
// Usually it is just one event, but it can be more.
7979
assert.ok(ioEvents >= 3, `at least 3 stdout io events, got ${ioEvents}`);
8080

81-
checkInvocations(pipe1, { init: 1, before: 2, after: 2 },
81+
checkInvocations(pipe1, { init: 1, before: 1, after: 1 },
8282
'pipe wrap when sleep.spawn was called');
8383
checkInvocations(pipe2, { init: 1, before: ioEvents, after: ioEvents },
8484
'pipe wrap when sleep.spawn was called');

0 commit comments

Comments
 (0)