Skip to content

Commit 67368d8

Browse files
committed
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 c4f80c1 commit 67368d8

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() {
@@ -533,7 +533,7 @@ function masterInit() {
533533
}
534534

535535
function send(worker, message, handle, cb) {
536-
sendHelper(worker.process, message, handle, cb);
536+
return sendHelper(worker.process, message, handle, cb);
537537
}
538538
}
539539

@@ -701,7 +701,7 @@ function workerInit() {
701701
};
702702

703703
function send(message, cb) {
704-
sendHelper(process, message, null, cb);
704+
return sendHelper(process, message, null, cb);
705705
}
706706

707707
function _disconnect(masterInitiated) {
@@ -747,7 +747,7 @@ function sendHelper(proc, message, handle, cb) {
747747
if (cb) callbacks[seq] = cb;
748748
message.seq = seq;
749749
seq += 1;
750-
proc.send(message, handle);
750+
return proc.send(message, handle);
751751
}
752752

753753

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)