diff --git a/lib/cluster.js b/lib/cluster.js index 21916e70b2..7e65fe222b 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -740,6 +740,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; diff --git a/test/parallel/test-cluster-process-disconnect.js b/test/parallel/test-cluster-process-disconnect.js new file mode 100644 index 0000000000..f83dd00949 --- /dev/null +++ b/test/parallel/test-cluster-process-disconnect.js @@ -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(); + })); +}