summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/child_process.js2
-rw-r--r--test/simple/test-child-process-disconnect.js10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index f7312215cd..4b37350e43 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -498,7 +498,7 @@ function setupChannel(target, channel) {
return;
}
- finish();
+ process.nextTick(finish);
};
channel.readStart();
diff --git a/test/simple/test-child-process-disconnect.js b/test/simple/test-child-process-disconnect.js
index 162e7dde8b..301034c56e 100644
--- a/test/simple/test-child-process-disconnect.js
+++ b/test/simple/test-child-process-disconnect.js
@@ -27,6 +27,16 @@ var net = require('net');
// child
if (process.argv[2] === 'child') {
+ // Check that the 'disconnect' event is deferred to the next event loop tick.
+ var disconnect = process.disconnect;
+ process.disconnect = function() {
+ disconnect.apply(this, arguments);
+ // If the event is emitted synchronously, we're too late by now.
+ process.once('disconnect', common.mustCall(disconnectIsNotAsync));
+ // The funky function name makes it show up legible in mustCall errors.
+ function disconnectIsNotAsync() {}
+ };
+
var server = net.createServer();
server.on('connection', function(socket) {