cluster: fix race condition setting suicide prop
authorSantiago Gimeno <santiago.gimeno@gmail.com>
Fri, 18 Dec 2015 18:13:50 +0000 (19:13 +0100)
committerMyles Borins <mborins@us.ibm.com>
Mon, 15 Feb 2016 19:30:23 +0000 (11:30 -0800)
commitf8a676ed59180f0a61828c0e0441656398016309
tree4fb6452cebb350d5b5b2430b85a3516263745dac
parent48c2783421f7d1d4ef56f57aa5bb38e3b6c584ec
cluster: fix race condition setting suicide prop

There is no guarantee that the `suicide` property of a worker in the
master process is going to be set when the `disconnect` and `exit`
events are emitted.

To fix it, wait for the ACK of the suicide message from the master
before disconnecting the worker. Also, there's no need to send the
suicide message from the worker if the disconnection has been
initiated in the master.

Add `test-cluster-disconnect-suicide-race` that forks a lot of workers
to consistently reproduce the issue this patch tries to solve.

Modify `test-regress-GH-3238` so it checks both the `kill` and
`disconnect` cases. Also take into account that the `disconnect` event
may be received after the `exit` event.

PR-URL: https://github.com/nodejs/node/pull/4349
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
lib/cluster.js
test/parallel/test-regress-GH-3238.js
test/sequential/test-cluster-disconnect-suicide-race.js [new file with mode: 0644]