-
-
Save sam-github/7574579 to your computer and use it in GitHub Desktop.
demonstrate how cluster in node v0.10 doesn't close server handles when no workers need them
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') | |
var net = require('net'); | |
var spawn = require('child_process').spawn; | |
if(cluster.isMaster) { | |
cluster.fork() | |
cluster.on('exit', function() { | |
//cluster.disconnect(); // if .disconnect() is called, it closes the serverHandlers | |
setTimeout(function() { | |
spawn('nc', ['-v', '-l', '4444'], {stdio: 'inherit'}) | |
}, 1000) | |
}) | |
} else { | |
var port = 4444; | |
var server = net.createServer() | |
.listen(port, function() { | |
console.log('pid %d listen on:', process.pid, port); | |
process.nextTick(function() { | |
process.disconnect() | |
}) | |
}) | |
.on('error', function(er) { | |
console.log('listen error:', er) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment