joyent/node — Issue #2329: cluster: kill of master process via console doesn't kill workers
Author: pity
Created: 2011-12-14 10:02:24+00:00
State: open

After some unexpected necessary kill of master process, workers are still running. Should cluster module kill them also?

Lets have example dummy script:

```javascript
var cluster = require('cluster');
var http = require('http');

if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < 4; i++) {
cluster.fork();
}

cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
// Worker processes have a http server.
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
}
```

executing the script:

```
test@ubuntu:~/workspace/tmp$ node cluster_test.js
```

Making list of node preocesses:

```
test@ubuntu:~$ ps aux | grep node
test 1919 0.7 1.4 56140 7432 pts/0 Sl+ 10:51 0:00 node cluster_test.js
test 1921 0.8 1.4 55972 7352 pts/0 Sl+ 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1922 0.8 1.4 56164 7360 pts/0 Sl+ 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1923 0.8 1.4 55972 7360 pts/0 Sl+ 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1924 0.8 1.4 55972 7368 pts/0 Sl+ 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1935 0.0 0.1 4184 804 pts/1 S+ 10:51 0:00 grep --color=auto node
```

Killing master:

```
kill -9 1919
```

Output of node script:

```
test@ubuntu:~/workspace/tmp$ node cluster_test.js
Killed
```

List of still runing workers

```
test@ubuntu:~$ ps aux | grep node
test 1921 0.4 1.4 55972 7352 pts/0 Sl 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1922 0.4 1.4 56164 7360 pts/0 Sl 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1923 0.3 1.4 55972 7360 pts/0 Sl 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1924 0.3 1.4 55972 7368 pts/0 Sl 10:51 0:00 /usr/local/bin/node /home/test/workspace/tmp/cluster_test.js
test 1938 0.0 0.1 4184 804 pts/1 S+ 10:52 0:00 grep --color=auto node
```