From d38d96eb610b50bdbfe869a6e7688e346984c0fa Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 8 May 2010 23:28:26 -0700 Subject: [PATCH] Don't emit 'exit' twice from child process --- lib/child_process.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index b2ad2b619fa..ebca206df42 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -99,14 +99,22 @@ function ChildProcess () { var stdout = this.stdout = new Stream(); var stderr = this.stderr = new Stream(); - function onClose () { - if (gotCHLD && !stdout.readable && !stderr.readable) { + var stderrClosed = false; + var stdoutClosed = false; + + stderr.addListener('close', function () { + stderrClosed = true; + if (gotCHLD && stdoutClosed) { self.emit('exit', exitCode, termSignal); } - } + }); - stderr.addListener('close', onClose); - stdout.addListener('close', onClose); + stdout.addListener('close', function () { + stdoutClosed = true; + if (gotCHLD && stderrClosed) { + self.emit('exit', exitCode, termSignal); + } + }); internal.onexit = function (code, signal) { gotCHLD = true;