In a TCP connection the end that performs the active close is required to stay in TIME_WAIT state for 2MSL of time. Why exactly does it need to be 2MSL? Many people said that one MSL is for the final ACK and the other MSL is for retransmitted FIN. But, the RTO of FIN is way shorter than MSL, and the FIN doesn't need to wait for an MSL to be retransmitted. So, their explanation doesn't make sense to me. Can anyone present a specific example of how segments are exchanged during that time?
Why does the TIME_WAIT state exist?
The book <<UNIX Network Programming(Volume1,3rd)>> give an answer:
There are two reasons for the TIME_WAIT state:
- To implement TCP's full-duplex connection termination reliably
- To allow old duplicate segments to expire in the network
I think this is also the answer to this question(Why TIME_WAIT state need to be 2MSL long?)
First look at reason 1. In order to reliably terminate the full-duplex connection, suppose that the last ACK sent by the client in Figure 1 is lost, and the server will retransmit the FIN. In order to receive this timeout and retransmitted FIN, the client needs TIME_WAIT Status; does the TIME_WAIT status have to be 2MSL? In fact, this depends on the server-side FIN timeout retransmission time RTO. If RTO is less than MSL, then TIME_WAIT state MSL is enough. If RTO is greater than 2MSL then TIME_WAIT state 2MSL is not enough, so only when RTO is between MSL and 2MSL , Reason 1 for the existence of the TIME_WAIT state is the reason why the time of TIME_WAIT is 2MSL. In fact, in general, RTO is much smaller than MSL, but considering the worst case, RTO is 2MSL, so the TIME_WAIT state is 2MSL to ensure that the worst case can also receive the FIN that is retransmitted over time.
The time of TIME_WAIT is another important reason for 2MSL. Reason 2, in order to ensure that all packets generated during the duration of this connection disappear from the network, that is, to ensure that when a new TCP connection is established, the old duplicate packets from the connection are already in Disappeared from the network. Some people here may have a question: After the client replies to the last ACK, it feels that all packets can disappear with one MSL. Why do all packets of 2MSL disappear? The reason is:
Suppose that the client sends an ACK just after one MSL time, and the server just starts to retransmit the FIN over time before receiving the ACK, so if the FIN disappears, 2MSL is needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With