Search code examples
tcpproxytcpclienttcpserver

CLOSE_WAIT state in server


In one of our server, many connections are in CLOSE_WAIT. I understand that it means the other side of the connection is closed and now it is upto the server to send the FIN and change the state to LAST_ACK and close the connection.

My questions are:

  1. What if the client send a RST when the server is in CLOSE_WAIT state?
  2. After the client has send the FIN and if the server still wants to send more data, what would be the state of the server in this case?

Solution

  • What if the client send a RST when the server is in CLOSE_WAIT state?

    The server would still have the socket open so the state won't change. CLOSE_WAIT means that the local TCP is waiting for the local application to close the socket.

    After the client has send the FIN and if the server still wants to send more data, what would be the state of the server in this case?

    The FIN means the client has stopped sending. It doesn't imply that the client can't receive. If the server tries to send, either:

    1. It will succeed, which means the client only did shutdown for output, or

    2. It will provoke an RST from the client, which means the client closed the socket. The RST probably won't happen on the first send but on a subsequent one, due to TCP buffering.