diff --git a/lib/cluster.js b/lib/cluster.js index 175645f713f701..68a772a74a9b59 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -749,7 +749,7 @@ function internal(worker, cb) { return function(message, handle) { if (message.cmd !== 'NODE_CLUSTER') return; var fn = cb; - if (message.ack !== undefined) { + if (message.ack !== undefined && callbacks[message.ack] !== undefined) { fn = callbacks[message.ack]; delete callbacks[message.ack]; } diff --git a/test/parallel/test-cluster-invalid-message.js b/test/parallel/test-cluster-invalid-message.js new file mode 100644 index 00000000000000..006c80a7aae8fc --- /dev/null +++ b/test/parallel/test-cluster-invalid-message.js @@ -0,0 +1,22 @@ +'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); + assert.strictEqual(signal, null); + })); + + worker.on('online', () => { + worker.send({ + cmd: 'NODE_CLUSTER', + ack: -1 + }, () => { + worker.disconnect(); + }); + }); +}