2
When a TCP connection is closed at one end of the connection - the other end receives a FIN
and responds with an ACK
. This end of the connection then enters the CLOSE_WAIT
state. Once close()
is called at this end the TCP sends a FIN
packet and enters the LAST_ACK
state. However, it never enters the TIME_WAIT
state.
Now, let's suppose that the Host A calls close()
on the socket and sends a FIN
packet to Host B. Host A enters the FIN_WAIT_1
state. Host B receives the FIN
packet, sends an ACK
and then enters the CLOSE_WAIT
state. However, the ACK is dropped somewhere in an upstream router.
Meanwhile, Host B calls close()
(recall that Host B is in the CLOSE_WAIT
state) and sends a FIN
packet to Host A. Host B now enters the LAST_ACK
state. Host A receives the FIN
packet and replies with an ACK
. It then enters the CLOSING
state.
At the other end, Host B is still in the LAST_ACK
state. It then receives the ACK
from Host A and enters the CLOSED
state. Recall that the ACK
from Host B to Host A was dropped and that Host A has not resent it's FIN
packet. Host A resends it's FIN
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?