3

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?
Nimantha
  • 6,405
  • 6
  • 28
  • 69
ahamed101
  • 110
  • 2
  • 9

1 Answers1

1

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.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • thank you for your response. So, if the client has closed the connection and the server received a FIN, and if the server still has data to be send, what will be the TCP state of the server? – ahamed101 Jan 10 '14 at 00:36
  • I have one more doubt.The topology is CLIENT<>PROXY<>SEVER Between CLIENT & PROXY the connection is closed. Between PROXY & SERVER, the connection is still in EST state because SERVER is in CLOSE_WAIT. A half-closed connection if I am not wrong. The CLIENT sends a RESET to PROXY, because there was a zero window probe send by SERVER to PROXY which was then send to CLIENT. So, when the CLIENT sends the RESET, what should the PROXY do? RESET both the side and clean up the connection or should it ignore the RESET from CLIENT because that side of the connection is already closed? Thanks again. – ahamed101 Jan 14 '14 at 23:03
  • If the proxy encounters a 'connection reset' doing I/O with either peer it has no choice but to close its endpoint to that connection, a it no longer exists. – user207421 Jan 16 '14 at 10:09
  • @user207421 When a server in `CLOSE_WAIT` state receive a `RST`, it will set `sk->sk_err` to `EPIPE` and transition state to `CLOSE`. See [tcp_reset](https://github.com/torvalds/linux/blob/v4.15/net/ipv4/tcp_input.c#L3970-L3995) and [tcp_done](https://github.com/torvalds/linux/blob/v4.15/net/ipv4/tcp.c#L3479-L3497). – Poison Dec 09 '22 at 03:24