summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGireesh Punathil <gpunathi@in.ibm.com>2018-06-08 08:33:37 -0400
committerGireesh Punathil <gpunathi@in.ibm.com>2019-02-06 17:50:46 +0530
commitb1f82e4342f8a630b1ef83cd33781a725428f569 (patch)
tree86f05ec37b0ee204b606b35dc25f479963226f3d /lib
parent3732d7786bcb5722b9a4345e1345ff5ad81a7888 (diff)
downloadandroid-node-v8-b1f82e4342f8a630b1ef83cd33781a725428f569.tar.gz
android-node-v8-b1f82e4342f8a630b1ef83cd33781a725428f569.tar.bz2
android-node-v8-b1f82e4342f8a630b1ef83cd33781a725428f569.zip
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 <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/child_process.js6
1 files changed, 6 insertions, 0 deletions
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)