How come LAST_ACK doesn't enter CLOSE_WAIT?
My TCP's a little rusty but I believe it works like this:
When Host B calls close()
and sends its FIN
, the Sequence number on that FIN
will reveal to Host A that it missed a packet from Host B. So Host A won't Ack Host B's FIN
, it'll keep Ack'ing the last TCP segment that it successfully received from Host B. This will prompt Host B to retransmit the missing ACK
.
So Host A won't reach the CLOSING
state, because it won't consider the out-of-order FIN
to be truly received until it receives the missing ACK
that preceded it.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
When a TCP connection is closed at one end of the connection - the other end receives a
FIN
and responds with anACK
. This end of the connection then enters theCLOSE_WAIT
state. Onceclose()
is called at this end the TCP sends aFIN
packet and enters theLAST_ACK
state. However, it never enters theTIME_WAIT
state.Now, let's suppose that the Host A calls
close()
on the socket and sends aFIN
packet to Host B. Host A enters theFIN_WAIT_1
state. Host B receives theFIN
packet, sends anACK
and then enters theCLOSE_WAIT
state. However, the ACK is dropped somewhere in an upstream router.Meanwhile, Host B calls
close()
(recall that Host B is in theCLOSE_WAIT
state) and sends aFIN
packet to Host A. Host B now enters theLAST_ACK
state. Host A receives theFIN
packet and replies with anACK
. It then enters theCLOSING
state.At the other end, Host B is still in the
LAST_ACK
state. It then receives theACK
from Host A and enters theCLOSED
state. Recall that theACK
from Host B to Host A was dropped and that Host A has not resent it'sFIN
packet. Host A resends it'sFIN
packet on timeout - however Host B has closed the connection.Is Host A now stuck in the
CLOSING
state? Can the connection teardown continue? What happens next?