From 33b7fc250f061af42b595decf6c0edf360c5aae9 Mon Sep 17 00:00:00 2001 From: Andreas Madsen Date: Tue, 31 Jan 2012 17:14:42 +0100 Subject: [PATCH] child_process: do not disconnect on exit emit When using isolate the .fork would break because it had no .disconnect method. This remove the exit handler there would call .disconnect since it was not required. It also change .disconnect to throw if the channel is closed, this was not possible before because .disconnect would be called twice. --- lib/child_process.js | 7 +++---- test/simple/test-child-process-disconnect.js | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 4af4d4f4139..a1eac7744dd 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -158,7 +158,9 @@ function setupChannel(target, channel) { target.connected = true; target.disconnect = function() { - if (!this.connected) return; + if (!this.connected) { + this.emit('error', new Error('IPC channel is already disconnected')); + } // do not allow messages to be written this.connected = false; @@ -231,9 +233,6 @@ exports.fork = function(modulePath /*, args, options*/) { if (!options.thread) setupChannel(child, options.stdinStream); - // Disconnect when the child process exits. - child.once('exit', child.disconnect.bind(child)); - return child; }; diff --git a/test/simple/test-child-process-disconnect.js b/test/simple/test-child-process-disconnect.js index adb008d25fa..e490c0848d2 100644 --- a/test/simple/test-child-process-disconnect.js +++ b/test/simple/test-child-process-disconnect.js @@ -85,6 +85,7 @@ if (process.argv[2] === 'child') { // ready to be disconnected if (data === 'ready') { child.disconnect(); + assert.throws(child.disconnect.bind(child), Error); return; }