How to kill "CLOSE_WAIT" and "FIN_WAIT2" network connections

I creating a game using node.js and socket.io. All works good, but from time to time this game socket server didn`t response to any connections. When I go to Process information -> Files and connections (in webmin), then i see there is many connections with "CLOSE_WAIT" and "FIN_WAIT2" statuses. I think problem is in these connections, because game fail when there are about 1000 connections. Server OS Ubuntu Linux 12.04.

How to kill theese connections or how to increase max allowed connections?

To add to Jim answer, i think there is a problem in your client handling of closing of socket connections . It seems your client is not closing the sockets properly(both server initiated and client initiated close) and that is the reason your server has so many wait states

Linux has the SO_REUSEADDR option for setting socket parameters. It allows immediate reuse of the same port. Someone who knows your toolset can tell you how to set socket options. You may already know how. I do not know this toolset.

From older java docset: http://docs.oracle.com/javase/1.5.0/docs/guide/net/socketOpt.html

You don't need to kill connections or increase the number allowed. You need to fix a defect in the application on one side of the connection, specifically, the side which does not initiate the close.

See Figure 13 of RFC 793. Your programs are at step 3 of the close sequence. The side which you see in FIN-WAIT-2 is behaving correctly. It has initiated the close and the TCP stack has sent a FIN packet on the network. The side in CLOSE-WAIT has the defect. The TCP stack on that side has received and acknowledged the FIN packet, but the application has failed to notice. How the application is expected to detect that the remote side has closed the connection will depend on your platform. Unfortunately, I am old, and don't know node.js or socket.io.

What happens in C is that the socket appears readable, but a read() returns a zero-length packet. When the application sees this, it is expected to call close(). You will find something equivalent in the docs for node.js or socket.io.

When you find it, considering answering your own question here and accepting the answer.