Repository navigation
cluster: suicide flag is not set on master when calling disconnect from a worker #3238
Description
Activity
- addedclusterIssues and PRs related to the cluster subsystem.Issues and PRs related to the cluster subsystem.
on Oct 7, 2015 - addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Oct 13, 2015 - added 2 commits that reference this issue
on Nov 11, 2015 - added a commit that references this issue
on Dec 4, 2015 - added a commit that references this issue
on Dec 17, 2015 - added a commit that references this issue
on Dec 23, 2015 19 remaining items
- added a commit that references this issue
on Feb 15, 2016 - added a commit that references this issue
on Apr 2, 2016 Came across same problem. I set a flag called "isSuicide" of worker Object:
var cluster = require('cluster'); if (cluster.isMaster) { // Master forks and listens for events var worker = cluster.fork(); cluster.on('disconnect', function(worker){ worker.isSuicide = true; console.log("disconnect", worker.suicide); }); cluster.on('exit', function(worker){ worker.isSuicide && console.log("exit by suicide"); }); } else { // Worker just disconnects cluster.worker.disconnect(); }
Is this a good practice for all node versions?
all versions up to node v4 will print false.
Are you saying it will print true for v5 and later?
@zhongkai No, it is not good practice. Your code sets suicide when the IPC channel is disconnected, but the 0.10 behaviour does it only when the worker deliberately disconnected.
Change your line of code
cluster.worker.disconnect();tothow 'farewall, crule world', and your code will also set your customisSuicideproperty, which it should not.@sam-github Note that this issue was opened over a year ago and was supposedly fixed in f299d87. I don't know what the current behavior is or what is intended.
Ah, didn't notice that. So, should be fixed. @zhongkai On what node version did you come across this problem?
@sam-github , I'm sorry. I just want to make sure the solution is OK for version 0.12.x or not?
- added a commit that references this issue
on Mar 7, 2018 - added a commit that references this issue
on Mar 11, 2018 - added a commit that references this issue
on Mar 17, 2018 - added a commit that references this issue
on Mar 20, 2018 - added a commit that references this issue
on May 8, 2018 - added a commit that references this issue
on Oct 2, 2018 - added a commit that references this issue
on Jul 27, 2026
From the documentation:
worker.suicide:worker.disconnect():Repro:
In node v0.10, both log statements would print
trueforworker.suicide. In 41b75ca, which landed during the v0.11 branch, this was broken, and all versions up to node v4 will printfalse. This is becauseworker.disconnect(), when called from the worker, does not send thesuicidemessage anymore -- onlyworker.destroy()will send that message to the master.