Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantiago Gimeno <santiago.gimeno@gmail.com>2020-04-01 15:22:07 +0300
committerAnna Henningsen <anna@addaleax.net>2020-04-28 20:20:53 +0300
commit73324cf76a1898d45d887a44145e7ab12236c076 (patch)
tree453feb4dbc2d5dfa74d8a213a94ab46eff3e5fac /lib/internal/cluster
parentee9280a02a4f8810a2d4fd409d08266ce95f2184 (diff)
cluster: fix error on worker disconnect/destroy
Avoid sending multiple `exitedAfterDisconnect` messages when concurrently calling `disconnect()` and/or `destroy()` from the worker so `ERR_IPC_DISCONNECTED` errors are not generated. Fixes: https://github.com/nodejs/node/issues/32106 PR-URL: https://github.com/nodejs/node/pull/32793 Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/internal/cluster')
-rw-r--r--lib/internal/cluster/child.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js
index 250a82ecaba..74f30c0d2ec 100644
--- a/lib/internal/cluster/child.js
+++ b/lib/internal/cluster/child.js
@@ -228,16 +228,23 @@ function _disconnect(masterInitiated) {
// Extend generic Worker with methods specific to worker processes.
Worker.prototype.disconnect = function() {
- _disconnect.call(this);
+ if (![ 'disconnecting', 'destroying' ].includes(this.state)) {
+ this.state = 'disconnecting';
+ _disconnect.call(this);
+ }
+
return this;
};
Worker.prototype.destroy = function() {
- this.exitedAfterDisconnect = true;
+ if (this.state === 'destroying')
+ return;
+ this.exitedAfterDisconnect = true;
if (!this.isConnected()) {
process.exit(0);
} else {
+ this.state = 'destroying';
send({ act: 'exitedAfterDisconnect' }, () => process.disconnect());
process.once('disconnect', () => process.exit(0));
}