hi , I used ubuntu(12.04) + nodejs (v0.10.22) + socket.io (v0.9.14) to transmit messages.
There are ~300 simultaneous connections. After some hours (about 1 or 2 hours above, it doesn't show up immediately), some connections will persistent in the state CLOSE_WAIT or FIN_WAIT2.
And these un-dead connections grows linearly with time. The users will hard to connect socket server when the connections number reach the limit (Default 1024 - see also Linux TCP/IP tuning for scalability) , unless some connections released normally.
The following was socket service connections status, running about 3 hours.
1. Touch js file in regular periods
Using Nodemon Package to run js file, when change the file's last modified time, nodemon will restart service, and release all previous un-dead connections (CLOSEWAIT or FINWAIT2)
2. Increase connections limit
Try to let connections hard to reach limit.
3. Decrease keep-alive timeout
Let operation system to close connections automatically in the short time, but I'm not try it yet.
see also : Using TCP keepalive under Linux
I found some probably solution to fix the problem. But the above solutions were not really solved the persistent connections with state CLOSE_WAIT or FIN_WAIT2 problem. I could find this is a result of server(CLOSE_WAIT) or clients (FIN_WAIT2) not correctly closing connections. I think socket.io will force-close these incorrectly connection after some timeout. But it seems like not work correctly.
I try to reappear the state CLOSE_WAIT or FIN_WAIT2 problem in my test environment. But it never show up these connection situation.
- After connect socket server and disconnect network
- Connect socket server for a long time
I found @njam ask related question before (Many stale connections in state CLOSE_WAIT and FIN_WAIT2), but still can't find the solution. Does anyone know how to solve this problem??