From 6a62bb0070198b8640495a35599797b0e16b6bf2 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 26 May 2016 13:00:51 -0400 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/6998 Reviewed-By: James M Snell Reviewed-By: Ron Korving Reviewed-By: Ben Noordhuis --- lib/cluster.js | 8 ++++---- test/parallel/test-cluster-fork-env.js | 3 ++- test/parallel/test-cluster-worker-events.js | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/cluster.js b/lib/cluster.js index 77726079602a64..21916e70b2bd2b 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -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() { @@ -531,7 +531,7 @@ function masterInit() { } function send(worker, message, handle, cb) { - sendHelper(worker.process, message, handle, cb); + return sendHelper(worker.process, message, handle, cb); } } @@ -699,7 +699,7 @@ function workerInit() { }; function send(message, cb) { - sendHelper(process, message, null, cb); + return sendHelper(process, message, null, cb); } function _disconnect(masterInitiated) { @@ -745,7 +745,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/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 52d8ef45f4e88d..fadfd5356540b3 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; }