The cluster module cleans up automatically when the master receives a
signal. What happens in your example is that the master process
instructs the worker process to commit suicide. When the worker
process goes away, there is nothing to keep the event loop alive and
node.js subsequently exits (that's why you get the 'exit' event - it's
just a normal shutdown.)
Admittedly the above could be explained a little better in the cluster
module documentation. There is an open pull request for that that I
should probably merge. :-)
But anyway, to make a long story short: have a listener like the one
below in your code and you should be good. The implementation of
allWorkersGone() is left as an exercise to the reader. :-)
cluster.on('disconnect', function(worker) {
if (allWorkersGone()) cleanup();
});