(same I posted in SO also couple of days back)
I have below sample code where I am forking child processes, starting a TCP
server and closing the server after certain timeout. When I looked at TCP
connections after timeout, I still see that one connection is in listening
state.
Also there are no client connections on this server and I see that server's
'close' event is also firing for each worker.
Strangely the server accepts new connections also. How to close the TCP
server completely in cluster environment?
I am using node 0.10.31 version.
var net = require('net');
var cluster = require('cluster');var numCPUs =
require('os').cpus().length;if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}} else {
var server = net.createServer(function(sock) {
console.log('received connection...');
});
server.on('listening', function() {
console.log('listening....');
setTimeout(function() {
server.close();
}, 5000);
});
server.on('close', function() {
console.log('server closed');
});
server.listen('2222', '101.30.33.194');}
on running lsof after timeout to check tcp connections:
#lsof -ni -P | grep 2222
node 17228 root 14u IPv4 440505953 0t0 TCP
101.30.33.194:2222 (LISTEN)
--
-Phani
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/CAP1dm3%3D%2BxR06vovy%3DzBZaK7Vt2nJ01PV6s5vbteU_G3EWSL0Jw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.