One of the reasons for TIME_WAIT is to prevent old packets/duplicates, coming in late, to screw up subsequent connections on the same (src ip, src port, dst ip, dst port) quadruplet.

That makes sense, but I don't understand why it is only done for the side closing the connection.

Let's assume both connections have sent and received FINs and ACKs - aren't they in the same boat regarding old duplicates coming in? So why doesn't the other side protect itself with a TIME_WAIT state as well?

  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you can post and accept your own answer. – Ron Maupin Dec 17 '20 at 22:33

I don't understand why it is only done for the side closing the connection.

Remember that that when the first side sends a FIN, it is done sending, but it will still receive and process as long as the other side is willing to send, and sends ACKs for any segments received until the other side is done. It goes into the FIN-WAIT-1 state until it receives the ACK of its FIN, and the FIN-WAIT-2 state after it receives that ACK of its FIN. It cannot force the other side to close (except with RST), and it will receive and process until the connection is closed.

When the second side is done sending, it will send a FIN causing the the first side to send an ACK, then go into TIME-WAIT (2MSL) to make sure the second side received its ACK. After the second side receives the ACK, it also waits 2MSL. After those timeouts, each side closes the connection. This is actually symmetric as both side wait 2MSL before closing the connection.

Once the connection is closed, and any receipt of segments, by either side, after that requires a RST in reply. The timeout on the second side is to make sure that there are no out-of-order segments arriving that would cause a RST.

It is explained in RFC 793, Transmission Control Protocol, which is the definition of TCP. The originator of the first FIN goes into TIME-WAIT because "TIME-WAIT - represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request." After the last ACK of the last FIN, the sender of the last FIN must wait "Timeout=2MSL."

The states are explained on pages 21 and 22, and the Connection State diagram is on page 23.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.