From b1f82e4342f8a630b1ef83cd33781a725428f569 Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Fri, 8 Jun 2018 08:33:37 -0400 Subject: child_process: close pipe ends that are re-piped when t0 and t1 are spawned with t0's outputstream [1, 2] is piped into t1's input, a new pipe is created which uses a copy of the t0's fd. This leaves the original copy in Node parent, unattended. Net result is that when t0 produces data, it gets bifurcated into both the copies Detect the passed handle to be of 'wrap' type and close after the native spawn invocation by which time piping would have been over. Fixes: https://github.com/nodejs/node/issues/9413 Fixes: https://github.com/nodejs/node/issues/18016 PR-URL: https://github.com/nodejs/node/pull/21209 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- lib/internal/child_process.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 498dbf6a1c..cb0d8ec6b6 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -384,6 +384,12 @@ ChildProcess.prototype.spawn = function(options) { continue; } + // stream is already cloned and piped, so close + if (stream.type === 'wrap') { + stream.handle.close(); + continue; + } + if (stream.handle) { // when i === 0 - we're dealing with stdin // (which is the only one writable pipe) -- cgit v1.2.3