Skip to content

Commit b902fda

Browse files
cjihrigMyles Borins
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 1f05a05 commit b902fda

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
@@ -48,7 +48,7 @@ Worker.prototype.kill = function() {
4848
};
4949

5050
Worker.prototype.send = function() {
51-
this.process.send.apply(this.process, arguments);
51+
return this.process.send.apply(this.process, arguments);
5252
};
5353

5454
Worker.prototype.isDead = function isDead() {
@@ -518,7 +518,7 @@ function masterInit() {
518518
}
519519

520520
function send(worker, message, handle, cb) {
521-
sendHelper(worker.process, message, handle, cb);
521+
return sendHelper(worker.process, message, handle, cb);
522522
}
523523
}
524524

@@ -684,7 +684,7 @@ function workerInit() {
684684
};
685685

686686
function send(message, cb) {
687-
sendHelper(process, message, null, cb);
687+
return sendHelper(process, message, null, cb);
688688
}
689689

690690
function _disconnect(masterInitiated) {
@@ -732,7 +732,7 @@ function sendHelper(proc, message, handle, cb) {
732732
if (cb) callbacks[seq] = cb;
733733
message.seq = seq;
734734
seq += 1;
735-
proc.send(message, handle);
735+
return proc.send(message, handle);
736736
}
737737

738738

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)