Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
child_process: guard against race condition
It is possible that the internal hnadleMessage() might try to send to
a channel that has been closed. The result can be an AssertionError.
Guard against this.

Fixes: #4205
  • Loading branch information
Trott committed Dec 24, 2015
commit c01bedbadda7cd6fa7a761a1b526307862f8ef01
3 changes: 3 additions & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ function setupChannel(target, channel) {

const INTERNAL_PREFIX = 'NODE_';
function handleMessage(target, message, handle) {
if (!target._channel)
return;

var eventName = 'message';
if (message !== null &&
typeof message === 'object' &&
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-cluster-disconnect-race.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

// Ref: https://github.com/nodejs/node/issues/4205

const common = require('../common');
const net = require('net');
const cluster = require('cluster');
cluster.schedulingPolicy = cluster.SCHED_NONE;

if (cluster.isMaster) {
var worker1, worker2;

worker1 = cluster.fork();
worker1.on('message', common.mustCall(function() {
worker2 = cluster.fork();
worker1.disconnect();
worker2.on('online', common.mustCall(worker2.disconnect));
}));

return;
}

var server = net.createServer();

server.listen(common.PORT, function() {
process.send('listening');
});