FIN
In short: A TCP flag with which one side signals that it will send no more data — the start of an orderly connection teardown.
In more detail: Since a TCP connection consists of two independent data directions, each side has to end its own direction separately with FIN — which is why a complete, orderly teardown typically runs via a four-way handshake (FIN/ACK from both sides). This means one side can already be “done sending” (FIN sent) while it’s still receiving data from the other side — this state is called a half-close.
In Depth
The typical sequence in an orderly connection teardown:
- The client sends
FIN— “I have no more data to send” - The server acknowledges with
ACKand can itself still continue sending (half-close state) - As soon as the server is also finished, it sends its own
FIN - The client acknowledges with
ACK— the connection is completely closed
After the last ACK, the connection remains in the TIME_WAIT state for a while on the side that sent FIN first (typically 30-120 seconds) before the socket is really released — this prevents “stray” packets of an old connection arriving late from being wrongly assigned to a new connection that happens to reuse the same port. On servers with very many short-lived connections (e.g. web servers under load), a large number of sockets in the TIME_WAIT state can actually become a practical problem, since port numbers remain temporarily blocked as a result.
In contrast to an orderly teardown via FIN, an RST ends the connection immediately, with no regard for data not yet acknowledged — FIN says “I’m done”, RST says “this connection no longer exists for me, ignore everything”.
See also: RST, Three-way handshake, TCP, SYN, ACK