Skip to content

Commit

Permalink
cluster: expose result of send()
Browse files Browse the repository at this point in the history
There are several places in the cluster module where a version
of process.send() is called, but the result is swallowed. Most
of these cases are internal, but Worker.prototype.send(), which
is publicly documented, also suffers from this problem. This
commit exposes the return value to facilitate better error
handling, and bring Worker.prototype.send() into compliance
with the documentation.

PR-URL: #6998
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ron Korving <ron@ronkorving.nl>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
cjihrig committed May 31, 2016
1 parent c4f80c1 commit 67368d8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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() {
Expand Down Expand Up @@ -533,7 +533,7 @@ function masterInit() {
}

function send(worker, message, handle, cb) {
sendHelper(worker.process, message, handle, cb);
return sendHelper(worker.process, message, handle, cb);
}
}

Expand Down Expand Up @@ -701,7 +701,7 @@ function workerInit() {
};

function send(message, cb) {
sendHelper(process, message, null, cb);
return sendHelper(process, message, null, cb);
}

function _disconnect(masterInitiated) {
Expand Down Expand Up @@ -747,7 +747,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);
}


Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-cluster-fork-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-cluster-worker-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 67368d8

Please sign in to comment.