Armīns Nikolajevs
Armīns Nikolajevs

Reputation: 107

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

I created a game using node.js and socket.io. All works well, but from time to time this game socket server doesn't respond to any connections. When I go to Process information -> Files and connections (in webmin), then I see there are many connections with CLOSE_WAIT and FIN_WAIT2 statuses. I think the problem is in these connections, because game fails when there are about 1,000 connections. Server OS is Ubuntu Linux 12.04.

How can I kill these connections or increase maximum allowed connections?

Upvotes: 3

Views: 8844

Answers (3)

jim mcnamara
jim mcnamara

Reputation: 16379

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

Upvotes: 0

fizzer
fizzer

Reputation: 13796

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.

Upvotes: 1

Pradheep
Pradheep

Reputation: 3819

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

Upvotes: 1

Related Questions