child_process: emit 'disconnect' asynchronously

Deferring I/O-triggered events to the next event loop tick is not just
a good idea, IT'S THE LAW!
pull/5010/head
Ben Noordhuis 2013-06-20 23:13:28 +02:00
parent 972465a3b0
commit b255f4c10a
2 changed files with 11 additions and 1 deletions

View File

@ -498,7 +498,7 @@ function setupChannel(target, channel) {
return;
}
finish();
process.nextTick(finish);
};
channel.readStart();

View File

@ -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) {