Don't emit 'exit' twice from child process

pull/22966/head
Ryan Dahl 2010-05-08 23:28:26 -07:00
parent d7762dffe3
commit d38d96eb61
1 changed files with 13 additions and 5 deletions

View File

@ -99,14 +99,22 @@ function ChildProcess () {
var stdout = this.stdout = new Stream(); var stdout = this.stdout = new Stream();
var stderr = this.stderr = new Stream(); var stderr = this.stderr = new Stream();
function onClose () { var stderrClosed = false;
if (gotCHLD && !stdout.readable && !stderr.readable) { var stdoutClosed = false;
stderr.addListener('close', function () {
stderrClosed = true;
if (gotCHLD && stdoutClosed) {
self.emit('exit', exitCode, termSignal); self.emit('exit', exitCode, termSignal);
} }
} });
stderr.addListener('close', onClose); stdout.addListener('close', function () {
stdout.addListener('close', onClose); stdoutClosed = true;
if (gotCHLD && stderrClosed) {
self.emit('exit', exitCode, termSignal);
}
});
internal.onexit = function (code, signal) { internal.onexit = function (code, signal) {
gotCHLD = true; gotCHLD = true;