diff --git a/lib/cluster.js b/lib/cluster.js index 8e8bdefadf03c7..554868ffdeb415 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -48,7 +48,7 @@ Worker.prototype.kill = function() { }; Worker.prototype.send = function() { - this.process.send.apply(this.process, arguments); + return this.process.send.apply(this.process, arguments); }; Worker.prototype.isDead = function isDead() { @@ -518,7 +518,7 @@ function masterInit() { } function send(worker, message, handle, cb) { - sendHelper(worker.process, message, handle, cb); + return sendHelper(worker.process, message, handle, cb); } } @@ -684,7 +684,7 @@ function workerInit() { }; function send(message, cb) { - sendHelper(process, message, null, cb); + return sendHelper(process, message, null, cb); } function _disconnect(masterInitiated) { @@ -732,7 +732,7 @@ function sendHelper(proc, message, handle, cb) { if (cb) callbacks[seq] = cb; message.seq = seq; seq += 1; - proc.send(message, handle); + return proc.send(message, handle); } diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 3613bfd0efeec8..c81697546cebd4 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -504,8 +504,7 @@ function setupChannel(target, channel) { handle = undefined; } if (this.connected) { - this._send(message, handle, false, callback); - return; + return this._send(message, handle, false, callback); } const ex = new Error('channel closed'); if (typeof callback === 'function') { @@ -513,6 +512,7 @@ function setupChannel(target, channel) { } else { this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick. } + return false; }; target._send = function(message, handle, swallowErrors, callback) { @@ -577,7 +577,7 @@ function setupChannel(target, channel) { handle: null, message: message, }); - return; + return this._handleQueue.length === 1; } var req = new WriteWrap(); diff --git a/test/parallel/test-child-process-send-returns-boolean.js b/test/parallel/test-child-process-send-returns-boolean.js new file mode 100644 index 00000000000000..b751846947822c --- /dev/null +++ b/test/parallel/test-child-process-send-returns-boolean.js @@ -0,0 +1,9 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const fork = require('child_process').fork; + +const n = fork(common.fixturesDir + '/empty.js'); + +const rv = n.send({ hello: 'world' }); +assert.strictEqual(rv, true); diff --git a/test/parallel/test-cluster-fork-env.js b/test/parallel/test-cluster-fork-env.js index fb58daee0cffdb..17b7af3d061926 100644 --- a/test/parallel/test-cluster-fork-env.js +++ b/test/parallel/test-cluster-fork-env.js @@ -4,11 +4,12 @@ var assert = require('assert'); var cluster = require('cluster'); if (cluster.isWorker) { - cluster.worker.send({ + const result = cluster.worker.send({ prop: process.env['cluster_test_prop'], overwrite: process.env['cluster_test_overwrite'] }); + assert.strictEqual(result, true); } else if (cluster.isMaster) { var checks = { diff --git a/test/parallel/test-cluster-worker-events.js b/test/parallel/test-cluster-worker-events.js index 0efad0e963e35c..e85ea8f4a04754 100644 --- a/test/parallel/test-cluster-worker-events.js +++ b/test/parallel/test-cluster-worker-events.js @@ -14,7 +14,8 @@ if (cluster.isMaster) { process.exit(0); }); - worker.send('SOME MESSAGE'); + const result = worker.send('SOME MESSAGE'); + assert.strictEqual(result, true); return; }