Created
March 31, 2015 19:39
-
-
Save Olegas/c2e5550911cbe8b96dae to your computer and use it in GitHub Desktop.
io.js worker disconnect bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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