Skip to main content
Tweeted twitter.com/StackNetworkEng/status/1436570200103653379
edited tags
Link
Ron Maupin
  • 101.1k
  • 26
  • 123
  • 199
Source Link
wlnirvana
  • 205
  • 3
  • 7

Why is the last ACK needed in TCP four way termination

As per title. Sorry if this is a duplicate question, but in the numerous posts online, I could only find how a connection is torn down, but not (convincingly) why it is done in such a way.


1. A -----FIN-----> B
2. A <----ACK------ B
3. A <----FIN------ B
4. A -----ACK-----> B        <====== Why is this one necessary?

======if 3 or 4 lost=======
5. A <....FIN...... B
6. A .....ACK.....> B

It seems B can shutdown the socket as soon as it sends out its FIN(3) because

  1. if the FIN(3) is not lost, all is well.
  2. if it is lost, A can timeout anyway and close the connection. One can argue that if this does happen, A will have to wait for a very long time. But B bears some risk with this last ACK(4) as well. Suppose the connection suddenly goes down (though with low probability) right after A sends out the last ACK(4), causing B unable to receive it. Then B will have to wait and timeout, too. Since both approaches are flawed, why not save this last ACK?

My guess

I think the only exception is that there is a reasonably high chance of packet loss such that both FIN(3) and ACK(4) won't arrive.

If FIN(3) is lost, receiving nothing back from A, B will resend its new FIN(5).

Similarly, if ACK(4) is lost, B will think that its FIN(3) is lost and resend the FIN(5) as well. A, though having sent out ACK(4), is supposed in the TIME-WAIT status, will hopefully receive this new FIN(5) and resend an ACK(6).

It seems only if the scenario described above happens reasonably frequently, will the last ACK(4) have a significant impact.