Skip to content

Commit

Permalink
cluster: don't send messages if no IPC channel
Browse files Browse the repository at this point in the history
Avoid sending messages if the IPC channel is already disconnected. It
avoids undesired errors when calling `process.disconnect` when there are
still pending IPC messages.

PR-URL: #7132
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
santigimeno authored and Myles Borins committed Jul 12, 2016
1 parent 4e6cbde commit c7a3424
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ function workerInit() {
var seq = 0;
var callbacks = {};
function sendHelper(proc, message, handle, cb) {
if (!proc.connected)
return false;

// Mark message as internal. See INTERNAL_PREFIX in lib/child_process.js
message = util._extend({ cmd: 'NODE_CLUSTER' }, message);
if (cb) callbacks[seq] = cb;
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-cluster-process-disconnect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');

if (cluster.isMaster) {
const worker = cluster.fork();
worker.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0, 'worker did not exit normally');
assert.strictEqual(signal, null, 'worker did not exit normally');
}));
} else {
const net = require('net');
const server = net.createServer();
server.listen(common.PORT, common.mustCall(() => {
process.disconnect();
}));
}

0 comments on commit c7a3424

Please sign in to comment.