Skip to content

Commit 33b7fc2

Browse files
AndreasMadsenisaacs
authored andcommitted
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.
1 parent 03c4aa6 commit 33b7fc2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/child_process.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ function setupChannel(target, channel) {
158158

159159
target.connected = true;
160160
target.disconnect = function() {
161-
if (!this.connected) return;
161+
if (!this.connected) {
162+
this.emit('error', new Error('IPC channel is already disconnected'));
163+
}
162164

163165
// do not allow messages to be written
164166
this.connected = false;
@@ -231,9 +233,6 @@ exports.fork = function(modulePath /*, args, options*/) {
231233

232234
if (!options.thread) setupChannel(child, options.stdinStream);
233235

234-
// Disconnect when the child process exits.
235-
child.once('exit', child.disconnect.bind(child));
236-
237236
return child;
238237
};
239238

test/simple/test-child-process-disconnect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ if (process.argv[2] === 'child') {
8585
// ready to be disconnected
8686
if (data === 'ready') {
8787
child.disconnect();
88+
assert.throws(child.disconnect.bind(child), Error);
8889
return;
8990
}
9091

0 commit comments

Comments
 (0)