From 1d9070051415053a2ed286840cfd77e5d98fed1e Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 6 Feb 2018 18:31:14 +0100 Subject: [PATCH] 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 `libuv@1.19.0` and specifically this commit: https://github.com/libuv/libuv/commit/fd049399aa4ed8495928e375466970d98cb42e17. PR-URL: https://github.com/nodejs/node/pull/18701 Refs: https://github.com/libuv/libuv/pull/1655 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig --- lib/internal/child_process.js | 12 +----------- test/async-hooks/test-pipewrap.js | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index a0409f72c29de0..a2d2012e109ff7 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -227,17 +227,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 }); } diff --git a/test/async-hooks/test-pipewrap.js b/test/async-hooks/test-pipewrap.js index 550de7907a168a..066458841fabab 100644 --- a/test/async-hooks/test-pipewrap.js +++ b/test/async-hooks/test-pipewrap.js @@ -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');