{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/3238","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/3238/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/3238/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/3238/events","html_url":"https://github.com/nodejs/node/issues/3238","id":110250325,"number":3238,"title":"cluster: suicide flag is not set on master when calling disconnect from a worker","user":{"login":"dpatti","id":458155,"avatar_url":"https://avatars.githubusercontent.com/u/458155?v=3","gravatar_id":"","url":"https://api.github.com/users/dpatti","html_url":"https://github.com/dpatti","followers_url":"https://api.github.com/users/dpatti/followers","following_url":"https://api.github.com/users/dpatti/following{/other_user}","gists_url":"https://api.github.com/users/dpatti/gists{/gist_id}","starred_url":"https://api.github.com/users/dpatti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpatti/subscriptions","organizations_url":"https://api.github.com/users/dpatti/orgs","repos_url":"https://api.github.com/users/dpatti/repos","events_url":"https://api.github.com/users/dpatti/events{/privacy}","received_events_url":"https://api.github.com/users/dpatti/received_events","type":"User","site_admin":false},"labels":[{"id":155267477,"url":"https://api.github.com/repos/nodejs/node/labels/cluster","name":"cluster","color":"f7c6c7","default":false},{"id":151728674,"url":"https://api.github.com/repos/nodejs/node/labels/confirmed-bug","name":"confirmed-bug","color":"fc2929","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2015-10-07T15:25:07Z","updated_at":"2016-12-21T15:06:04Z","closed_at":"2015-11-11T16:22:12Z","body":"From the documentation:\n\n[`worker.suicide`](https://nodejs.org/api/cluster.html#cluster_worker_suicide):\n\n> Set by calling .kill() or .disconnect(), until then it is undefined.\n\n[`worker.disconnect()`](https://nodejs.org/api/cluster.html#cluster_worker_disconnect):\n\n> In a worker, this function will close all servers, wait for the 'close' event on those servers, and then disconnect the IPC channel.\n> \n> Causes .suicide to be set.\n\nRepro:\n\n``` javascript\nvar cluster = require('cluster');\n\nif (cluster.isMaster) {\n  // Master forks and listens for events\n  var worker = cluster.fork();\n  cluster.on('disconnect', function(){\n    console.log(\"disconnect\", worker.suicide);\n  });\n  cluster.on('exit', function(){\n    console.log(\"exit\", worker.suicide);\n  });\n} else {\n  // Worker just disconnects\n  cluster.worker.disconnect();\n}\n```\n\nIn node v0.10, both log statements would print `true` for `worker.suicide`. In 41b75ca9263f368db790fbdcc3963bb1a8c5cb7e, which landed during the v0.11 branch, this was broken, and all versions up to node v4 will print `false`. This is because `worker.disconnect()`, when called from the worker, does not send the `suicide` message anymore -- only `worker.destroy()` will send that message to the master.\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/268544957","html_url":"https://github.com/nodejs/node/issues/3238#issuecomment-268544957","issue_url":"https://api.github.com/repos/nodejs/node/issues/3238","id":268544957,"user":{"login":"zhongkai","id":637147,"avatar_url":"https://avatars.githubusercontent.com/u/637147?v=3","gravatar_id":"","url":"https://api.github.com/users/zhongkai","html_url":"https://github.com/zhongkai","followers_url":"https://api.github.com/users/zhongkai/followers","following_url":"https://api.github.com/users/zhongkai/following{/other_user}","gists_url":"https://api.github.com/users/zhongkai/gists{/gist_id}","starred_url":"https://api.github.com/users/zhongkai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhongkai/subscriptions","organizations_url":"https://api.github.com/users/zhongkai/orgs","repos_url":"https://api.github.com/users/zhongkai/repos","events_url":"https://api.github.com/users/zhongkai/events{/privacy}","received_events_url":"https://api.github.com/users/zhongkai/received_events","type":"User","site_admin":false},"created_at":"2016-12-21T15:06:04Z","updated_at":"2016-12-21T15:06:04Z","body":"Came across same problem. I set a flag called \"isSuicide\" of worker Object:\r\n```javascript\r\nvar cluster = require('cluster');\r\n\r\nif (cluster.isMaster) {\r\n  // Master forks and listens for events\r\n  var worker = cluster.fork();\r\n  cluster.on('disconnect', function(worker){\r\n    worker.isSuicide = true;\r\n    console.log(\"disconnect\", worker.suicide);\r\n  });\r\n  cluster.on('exit', function(worker){\r\n    worker.isSuicide && console.log(\"exit by suicide\");\r\n  });\r\n} else {\r\n  // Worker just disconnects\r\n  cluster.worker.disconnect();\r\n}\r\n```\r\nIs this a good practice for all node versions?"}}
{"actor":{"display_login":"zhongkai"}}