0
votes

I have a server on a well known TCP port to which bunch of clients are connected. Clients use the non blocking option to connect to the server.

When I kill the server process, the client sockets go to CLOSE_WAIT state. Now if I restart the server process and the clients try to connect again, the connect() call seems to block even though its supposed to be non-blocking..

The actual fix might actually be to close the socket when the server dies. But I am trying to understand the current behavior..

  • when an existing connection is in CLOSE_WAIT what is preventing a new connection being established ?
  • Why is the connect blocking even though is non-blocking option is set ?

This is seen with Linux 2.6.3x kernel..

2
2.6.3x kernel does not mean much. There is a considerable difference between 2.6.30 & 2.6.38. And upgrading the kernel to a 3.0.0 or 3.1.0 might make a difference.Basile Starynkevitch
Are you using SO_REUSEADDR? See stackoverflow.com/questions/775638/…Basile Starynkevitch
@BasileStarynkevitch 2.6.3x is sufficient info for this question. This seems to be a basic TCP/IP behavior which is unlikely to change often. Actual version is 2.6.32. And no, I am not going to try 3.0.0 on the assumption that the behavior might be different in 3.0.0Manohar
And what about the SO_REUSEADDR option?Basile Starynkevitch
Isn't the SO_REUSEADDR option useful at the server side, where the server wants to listen on the same socket right after a restart ? In my case server is able to bind to the same well-known port. But the issue is at the client side where they are not able to connect..Manohar

2 Answers

1
votes

It sounds like a bug in the client. If you set the socket non-blocking and then call connect, there is no reason the connect call should block. Can you paste the client code that creates the socket, sets it non-blocking, and calls connect? Also, are you positive it is blocked in the connect call itself?

0
votes

I believe your question is quite exactly answered here and related to SO_REUSEADDR. The other answer to a question about Using SO_REUSEADDR - What happens to previously open socket? is also relevant.