hetptis
hetptis

Reputation: 806

Prevent CLOSE_WAITs from client side when server not closing the connection properly

We have a application that connects to a external billing server. Once there was a outage in the server in the client side there was hundreds of connections in the CLOSE_WAIT state.

I have checked the client code. And it seems the client is closing TCP connections properly.

If this happened because server not closing the connection properly because of an issue form the server side, is there a way to prevent the client form keep sockets in CLOSE_WAIT state?

I also observed that the thread count and the cpu usage has gone up more than usual.

After a application restart, there were no CLOSE_WAIT build up even after several hours, and the thread count and cpu usage was back to normal.

If sever some times failed to close the connection properly, don't we have anything to do other than restarting the client to remove CLOSE_WAITs? ( I mean is there any code improvement which can prevent this problem in client side)

We use customised JDiameter code in the client side to connect to the billing server.

(We have no access to the server side code)

Upvotes: 2

Views: 3039

Answers (1)

user207421
user207421

Reputation: 310957

If this happened because server not closing the connection properly because of an issue form the server side ...

It didn't.

RFC 793 states: "CLOSE_WAIT - represents waiting for a connection termination request from the local user." It means that the peer has closed the connection: TCP has received a FIN, and it is waiting for the local application to do likewise.

If your have this problem at your own end of the connection, it indicates one thing: you aren't closing your own sockets. You are ignoring either EOS conditions or exceptions on your socket, and continuing to use it regardless.

Solution: don't. EOS means you have to stop reading and close the socket. Any IOException other than SocketTimeoutException means the same.

Upvotes: 3

Related Questions