Closing a connection and TCP's states
Each direction of a TCP connection closes on its own with a FIN and an ACK, and the side that closes first waits in TIME-WAIT for twice the maximum segment lifetime, so its last ACK can be resent and stray old segments die before the same address and port pair is reused.