There exist two ways of terminating a connection: asymmetric and symmetric release.
When one party wants to close, the complete connection is released.
Asymmetric release is abrupt and may result is data loss.
Telephone systems work in this way: when one party hangs up the connection is broken.
Each direction of the connection is closed independently of the other one.
Symmetric release treats the connection as two separate unidirectional connections.
Protocols typically use a 2-way handshake to close each direction independently.
One side initiates the release by sending a close packet to the other side.
This side responds with an acknowledgement packet. Now this direction is closed,
but still data can be send in the other direction.
After all data is send, the second direction is closed in the same way by a 2-way
handshake and connection release is finished.
The animation shows how a symmetric release works and how protocols handle
the loss of various release packets. Just select one of the different cases.
You'll see that for each transmitted close message a timer is started and
if no acknowledgment is received in time, the message is retransmitted.
If the final packet is lost, the situation is saved by a timer as well.
Try the 2-Army
problem, that illustrates problems with connection teardown.