joyent/node — Issue #2344: process still alive, when fork channel closed
Author: AndreasMadsen
Created: 2011-12-16 18:13:18+00:00
State: open

I know this use internal API, but the `cluster 2.0` module ( see: #2038 ) use this.

Here is a simpel master. It will fork a new "worker" just using `child_process` and when it gets a message from the worker it will disconnect it. The master should now die since there can't happen anything more, but it dose not!

```JavaScript

var child = require('child_process');
var util = require('util');

var worker = child.fork('worker.js');

worker.once('message', function () {
console.log('now disconnecing');

worker._channel.close();

//Lets se the content
console.log(util.inspect(worker._channel));

//try sending a message to the worker
try {
worker.send('say hi');
} catch (e) {
console.log('got an error, because the channel is closed :');
console.log(e);
}
});
```

And this is the worker. It will create a simpel http server just to keep it alive.

```JavaScript
var http = require('http');
var util = require('util');

//Keep the worker alive
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('PID: ' + process.pid + "\n");

//Lets see process._channel
res.write(util.inspect(process._channel));

res.end();

}).listen(8000, "127.0.0.1", function () {
process.send('hey master, please disconnect me');
});
```

Also when the master disconnect its worker the `worker._channel` is not `null` and the `worker._channel.destroyed` is `false`. However in in the worker the `worker._channel` property is `null`.