Skip to content

Commit 6a62bb0

Browse files
cjihrigrvagg
authored andcommitted
cluster: expose result of send()
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>
1 parent 2132d34 commit 6a62bb0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/cluster.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Worker.prototype.kill = function() {
6161
};
6262

6363
Worker.prototype.send = function() {
64-
this.process.send.apply(this.process, arguments);
64+
return this.process.send.apply(this.process, arguments);
6565
};
6666

6767
Worker.prototype.isDead = function isDead() {
@@ -531,7 +531,7 @@ function masterInit() {
531531
}
532532

533533
function send(worker, message, handle, cb) {
534-
sendHelper(worker.process, message, handle, cb);
534+
return sendHelper(worker.process, message, handle, cb);
535535
}
536536
}
537537

@@ -699,7 +699,7 @@ function workerInit() {
699699
};
700700

701701
function send(message, cb) {
702-
sendHelper(process, message, null, cb);
702+
return sendHelper(process, message, null, cb);
703703
}
704704

705705
function _disconnect(masterInitiated) {
@@ -745,7 +745,7 @@ function sendHelper(proc, message, handle, cb) {
745745
if (cb) callbacks[seq] = cb;
746746
message.seq = seq;
747747
seq += 1;
748-
proc.send(message, handle);
748+
return proc.send(message, handle);
749749
}
750750

751751

test/parallel/test-cluster-fork-env.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ var assert = require('assert');
44
var cluster = require('cluster');
55

66
if (cluster.isWorker) {
7-
cluster.worker.send({
7+
const result = cluster.worker.send({
88
prop: process.env['cluster_test_prop'],
99
overwrite: process.env['cluster_test_overwrite']
1010
});
1111

12+
assert.strictEqual(result, true);
1213
} else if (cluster.isMaster) {
1314

1415
var checks = {

test/parallel/test-cluster-worker-events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ if (cluster.isMaster) {
1414
process.exit(0);
1515
});
1616

17-
worker.send('SOME MESSAGE');
17+
const result = worker.send('SOME MESSAGE');
18+
assert.strictEqual(result, true);
1819

1920
return;
2021
}

0 commit comments

Comments
 (0)