Skip to content

Instantly share code, notes, and snippets.

@Olegas
Created March 31, 2015 19:39
Show Gist options
  • Save Olegas/c2e5550911cbe8b96dae to your computer and use it in GitHub Desktop.
Save Olegas/c2e5550911cbe8b96dae to your computer and use it in GitHub Desktop.
io.js worker disconnect bug
var cluster = require('cluster'),
net = require('net');
if (cluster.isMaster) {
console.log('Master started');
cluster.fork();
// Wait 10sec and disconnect worker
setTimeout(function(){
Object.keys(cluster.workers).forEach(function(id) {
console.log('Disconnecting worker');
cluster.workers[id].disconnect();
});
}, 10000);
cluster.on('disconnect', function() {
console.log('Cluster: worker is disconnected');
});
} else {
console.log('Worker started');
cluster.worker.on('disconnect', function(){
console.log('Worker disconnected');
});
net.createServer(function(req, res){
console.log('Incoming request');
}).listen(8080).on('close', function(){
console.log('Server is closed');
}).on('listening', function(){
console.log('Worker listening');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment