Skip to content

Commit 09349a8

Browse files
santigimenoMyles Borins
authored and
Myles Borins
committed
cluster: don't send messages if no IPC channel
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 6a08535 commit 09349a8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/cluster.js

+3
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ function workerInit() {
722722
var seq = 0;
723723
var callbacks = {};
724724
function sendHelper(proc, message, handle, cb) {
725+
if (!proc.connected)
726+
return false;
727+
725728
// Mark message as internal. See INTERNAL_PREFIX in lib/child_process.js
726729
message = util._extend({ cmd: 'NODE_CLUSTER' }, message);
727730
if (cb) callbacks[seq] = cb;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cluster = require('cluster');
5+
6+
if (cluster.isMaster) {
7+
const worker = cluster.fork();
8+
worker.on('exit', common.mustCall((code, signal) => {
9+
assert.strictEqual(code, 0, 'worker did not exit normally');
10+
assert.strictEqual(signal, null, 'worker did not exit normally');
11+
}));
12+
} else {
13+
const net = require('net');
14+
const server = net.createServer();
15+
server.listen(common.PORT, common.mustCall(() => {
16+
process.disconnect();
17+
}));
18+
}

0 commit comments

Comments
 (0)