TCP TIME WAIT – Purpose of TIME WAIT in TCP Connection Tear Down

tcp

I found that the reason the active closer enters TIME WAIT is to make sure that the final ACK is not lost. But how does it know if the final ACK is lost? Will the passive closer resend the FIN and then the active closer knows the ACK was lost? Here is a picture of the TCP FSM.

TCP FSM

Best Answer

Will the passive closer resend the FIN and then the active closer knows the ACK was lost?

Yes. Quoting from TCP/IP Illustrated Volume 1, in the TCP Connection Management section:

  1. To complete the close, the final segment contains an ACK for the last FIN. Note that if a FIN is lost, it is retransmitted until an ACK for it is received.

There is a timeout. When in LAST_ACK, the passive closer will resend FIN when there is a timeout, assuming that it was lost. If it was indeed lost, then the active closer will eventually receive the retransmitted FIN and enter TIME_WAIT. If the FIN was not lost but the final ACK was lost, then the active closer is in TIME_WAIT and receives FIN again. When this happens - receiving a FIN in TIME_WAIT - the ACK is retransmitted.

The timeout value in TIME_WAIT is NOT used for retransmission purposes. When there is a timeout in TIME_WAIT, it is assumed that the final ACK was successfully delivered because the passive closer didn't retransmit FIN packets. So, the timeout in TIME_WAIT is just an amount of time after which we can safely assume that if the other end didn't send anything, then it's because he received the final ACK and closed the connection.