Use it to see who ended a connection and how, and when a busy client cannot open new connections or sockets pile up in CLOSE-WAIT.
TCP Teardown, FIN/RST & TIME-WAIT
1. Which side sends the first FIN or RST?
2. What preceded it: a complete response, a long silence, the middle of a transfer?
3. RST mid-transfer → that side's application logs; check the reset really came from that host.
4. CLOSE-WAIT growing → the local application.
5. Client cannot connect → count TIME-WAIT; reuse connections.
exchange complete → one side sends FIN → acknowledged → other side sends FIN → acknowledged → first closer waits in TIME-WAIT → connection forgotten
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
tcpdump -ni eth0 'tcp[tcpflags] & (tcp-fin|tcp-rst) != 0' and host 192.0.2.10Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational verification Verify boundary
tcpdump -ni eth0 'tcp[tcpflags] & (tcp-fin|tcp-rst) != 0' and host 192.0.2.10
ss -tan state time-wait | wc -l
ss -tan state close-wait
sysctl net.ipv4.ip_local_port_range
The first prints only the closing packets, showing which side sends FIN or RST first. The ss commands count connections lingering in TIME-WAIT and list those in CLOSE-WAIT — the latter waiting for the local application to close. The sysctl line shows how many local ports a Linux client has to draw on.
In Wireshark, tcp.flags.fin == 1 || tcp.flags.reset == 1 finds the endings; follow the stream to see what preceded each.
Known-good: connections end with a FIN from each side after the exchange is complete, and no state accumulates.
Step 2 Failure isolation workflow Narrow the fault
- A reset ends the connection during a transfer. The sending side aborted: check that application's logs, and whether the reset really came from that host.
- A reset follows the client's FIN. The server had unread data or had already forgotten the connection; often harmless at the very end.
- A reset on the first packet after a long idle period. A device in the path, or the peer, timed the connection out.
- Connections in CLOSE-WAIT accumulate. The local application received the other side's FIN and never closes; an application fault.
- A client cannot open new connections to one server. Its ports are held in TIME-WAIT; reuse connections, or enlarge the port range.
- The response is cut short and ends with a FIN. The sender closed early; the fault is in the application, not the network.
- One side closes, the other keeps sending and gets resets. The application protocol's idea of who closes when is not being followed.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
FIN from both sides means both applications finished. A reset means something gave up — find out who and after what. CLOSE-WAIT that accumulates is an application not closing. TIME-WAIT is normal, but ties up the port pair.
tcpdump -ni <if> 'tcp[tcpflags] & (tcp-fin|tcp-rst) != 0' and host <ip>— only the closing packets.ss -tan state time-wait | wc -l— connections lingering after close.ss -tan state close-wait— waiting for the local application.sysctl net.ipv4.ip_local_port_range— a client's port range.
ReferenceWhat it is1 section · depth on demand
Mechanics & mental model
A TCP connection can end in two ways. The orderly way uses FIN: each side says "I am done sending" and the other acknowledges. The abrupt way uses RST: one side declares the connection over at once. After an orderly close, the side that closed first keeps the connection in memory for a while longer, in a state called TIME-WAIT.
ReferenceWhy it matters1 section · depth on demand
Why it matters operationally
How a connection ends says how the conversation went. A FIN from both sides means both applications finished what they intended. A reset means something gave up — an application, an operating system that no longer knew the connection, or a device in between. And when a busy system cannot open new connections, the cause is often the lingering TIME-WAIT entries of the ones it just closed.
ReferenceHow it works1 section · depth on demand
How it works
Orderly close.
1. Side A has nothing more to send and sends FIN.
2. Side B acknowledges. B may still send data — the connection is half closed.
3. When B is done too, it sends its own FIN.
4. A acknowledges.
Steps 2 and 3 are often combined into one packet, so three packets are common. Each FIN closes one direction only; a connection is fully closed when both have been sent and acknowledged.
TIME-WAIT. The side that sent the first FIN does not forget the connection immediately after step 4. It waits, typically about a minute, for two reasons: its last acknowledgment may have been lost, in which case the other side resends its FIN and needs an answer; and delayed packets from the old connection must not be mistaken for a new one using the same ports. During this time the same combination of addresses and ports cannot be reused. A client or proxy that opens and closes very many connections to one server can run out of local ports this way.
Abrupt close: RST. A reset ends the connection in both directions at once. Nothing is acknowledged, no TIME-WAIT follows, and data not yet delivered is discarded. A reset is sent when:
- an application closes a socket that still holds data it has not read;
- an application chooses to abort rather than close;
- a packet arrives for a connection the host does not know — after a restart or a timeout;
- a firewall or load balancer ends the connection on its own initiative.
Who closes first depends on the application protocol: in HTTP either side may, a database client usually does, and a server may close idle connections after a timeout.
Reading a capture. Note which side sends the first FIN or RST and what happened just before: the end of a complete response, a long silence, or the middle of a transfer.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Closing connections: FIN, RST and TIME-WAIT
TCP closes each direction separately. In RFC 9293, a FIN means "I have no more data to send". The receiver acknowledges it, advances its receive sequence past it, and passes an end-of-data signal to the application. Each FIN occupies one sequence number. The side that closes first ends in TIME-WAIT and must stay there for 2×MSL, which is four minutes with the RFC's MSL of 2 minutes. That delay ensures its final ACK can be resent if lost, and that old segments die out before the same ports are reused.
Orderly close versus abort
| FIN close | RST abort | |
|---|---|---|
| Data in flight | Delivered first | Discarded |
| Acknowledgement | Each FIN is acknowledged | RST is never acknowledged |
| Application sees | End of data, then close | "Connection reset" error |
| TIME-WAIT | Yes, on the side that closed first | No |
Half-close
After one side sends FIN, the other can keep sending data. Some protocols rely on this, for example a client signalling the end of its request. Middleboxes that time out half-closed sessions quickly can cut off such responses.
TIME-WAIT in practice
| Concern | Reality |
|---|---|
| "Thousands of TIME-WAIT sockets are a problem" | They are normal on busy clients and cost little memory |
| Port exhaustion on proxies | Real when one host opens many short connections to one destination |
| Fixes | Connection reuse (keep-alive, pooling), more source addresses, timestamp-based TIME-WAIT reuse |
RFC 9293 allows a new SYN to reopen a connection directly from TIME-WAIT, if its ISN is larger than the old connection's largest sequence number. It also recommends using timestamps to shorten TIME-WAIT safely.
host$ sudo tcpdump -ni eth0 'tcp[tcpflags] & (tcp-fin|tcp-rst) != 0 and host 10.30.0.15'
11:02:40.100 IP 10.110.0.64.50414 > 10.30.0.15.443: Flags [F.], seq 4019, ack 88213, length 0
11:02:40.101 IP 10.30.0.15.443 > 10.110.0.64.50414: Flags [F.], seq 88213, ack 4020, length 0
11:02:40.101 IP 10.110.0.64.50414 > 10.30.0.15.443: Flags [.], ack 88214, length 0
host$ ss -tan state time-wait | wc -l
host$ sysctl net.ipv4.tcp_tw_reuse net.ipv4.ip_local_port_range
The three lines show a complete close: FIN from the client, FIN plus ACK from the server, and the client's final ACK. The client is now in TIME-WAIT.
Documented example, not captured output.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Network & Protocols → TCP Teardown, FIN/RST & TIME-WAIT. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/rfc/rfc9293.html · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Operational notes
Former standalone Cheat Sheet content now lives directly inside the Topic where it belongs.
TCP FIN / RST / TIME-WAIT
Connection close evidence.
1. Identify first FIN/RST sender.
2. Read both socket states.
3. FIN = orderly half-close; RST = abort.
4. CLOSE-WAIT → local app has not closed.
5. TIME-WAIT is often normal after active close.