TCP Resets: Closed Ports, Aborts, Half-Open Connections and TIME-WAIT Assassination
When TCP sends a reset and how receivers judge one: closed ports, drop versus reject, SO_LINGER aborts, closing with unread data, half-open connections after a crash, TIME-WAIT assassination, and the RFC 5961 challenge ACK, all reproduced in the lab.
kvi5hnuCode Sprout team member14 min readOn this page
A FIN ends a connection politely: all data is delivered, then each side says goodbye. A segment with the RST (reset) bit set ends it immediately. A reset means "this connection is not valid here": it isn't acknowledged, it carries no data the receiver keeps, and any data still queued in either direction is thrown away. The application on the receiving side sees an error, usually "Connection refused" or "Connection reset by peer".
This article reproduces every common cause of a reset, then shows how a receiver decides whether to believe one.
A SYN to a closed port
When a SYN arrives for a port where nothing is listening, TCP answers with a reset. (UDP uses an ICMP Port Unreachable message for the same situation, as article 45 showed.) In the lab, the client connected to port 9999 on the server, where nothing listened. The capture shows raw sequence numbers. The dotted column has one position per flag, as in article 59: S is SYN, A is ACK, R is RST and P is PSH:
1 0.000 192.0.2.10:54952 > 198.51.100.10:9999 ··········S· seq=3131756572 ack=0 len=0
2 0.064 198.51.100.10:9999 > 192.0.2.10:54952 ·······A·R·· seq=0 ack=3131756573 len=0
The client's connect() failed one round trip later:
connect() failed after 68 ms: [Errno 111] Connection refused
Look at the numbers in the reset. The SYN didn't have the ACK bit set, so the reset can't use an ACK number from it as its own sequence number. Instead, the rule is:
- If the incoming segment has no ACK, the reset has sequence number 0, the ACK bit set, and an ACK number of the incoming sequence number plus the segment's length. A SYN counts as one, so here
ackis the ISN plus 1. - If the incoming segment has an ACK, the reset's sequence number is that ACK number, and it has no ACK bit.
Both rules make the reset acceptable to the sender, which checks it against the connection it thinks it has.
Drop versus reject on a firewall
Firewalls can block a port in two ways, and the difference shows up directly in the client's experience. In the lab, the server's nftables rules dropped SYNs to port 9001 and rejected those to port 9002 with a reset. Both ports had a listening server behind the firewall:
port 9001 (drop): TimeoutError after 3007 ms: timed out
port 9002 (reject with tcp reset): ConnectionRefusedError after 52 ms: [Errno 111] Connection refused
A dropped SYN looks like a host that isn't there: the client retransmits and waits, here until its 3-second timeout, and with no timeout up to the 2 minutes article 59 measured. A rejected SYN looks like a closed port, and the client knows within one round trip. Dropping hides the server's existence from scanners. Rejecting is kinder to legitimate clients on internal networks.
Aborting a connection
An application can end a connection with a reset on purpose, which is called an abortive release. Any data queued for sending is discarded, and the peer learns that the connection was aborted, not closed normally. The sockets API does it with the SO_LINGER option set to "on, with a timeout of 0" before close().
In the lab, the server sent data as fast as it could, and the client read about 100 KB and then aborted:
client: read 100744 bytes, then close() with SO_LINGER {on, 0}
The server's next send() failed:
server: send() failed after 144184 bytes: [Errno 104] Connection reset by peer
The capture at the client shows the reset and what followed:
104 0.237 192.0.2.10:39274 > 198.51.100.10:8000 ·······A·R·· seq=1 ack=100745 len=0
106 0.292 192.0.2.10:39274 > 198.51.100.10:8000 ·········R·· seq=1 ack=0 len=0
108 0.292 192.0.2.10:39274 > 198.51.100.10:8000 ·········R·· seq=1 ack=0 len=0
110 0.292 192.0.2.10:39274 > 198.51.100.10:8000 ·········R·· seq=1 ack=0 len=0
112 0.292 192.0.2.10:39274 > 198.51.100.10:8000 ·········R·· seq=1 ack=0 len=0
4 data segments from the server arrived after the abort
5 RST segments were sent by the client in total
The first reset (frame 104) carries ACK information. More of the server's data was already in flight, and when those segments reached the client, it no longer had a connection for them. It answered each with a plain reset, using the incoming ACK number as its sequence number. Nobody acknowledges a reset, so none of these segments got a reply.
Closing with unread data
A plainer way to cause a reset: close a socket while received data is still waiting in its receive buffer. RFC 1122 says TCP should send a reset in that case, because the application has clearly not processed everything the peer sent. In the lab, the client sent 6 bytes, and the server closed without reading them:
server: close() with 6 unread bytes in the receive buffer
client: recv() failed: [Errno 104] Connection reset by peer
1 0.000 192.0.2.10:53290 > 198.51.100.10:8001 ··········S· seq=0 ack=0 len=0
2 0.065 198.51.100.10:8001 > 192.0.2.10:53290 ·······A··S· seq=0 ack=1 len=0
3 0.065 192.0.2.10:53290 > 198.51.100.10:8001 ·······A···· seq=1 ack=1 len=0
4 0.065 192.0.2.10:53290 > 198.51.100.10:8001 ·······AP··· seq=1 ack=1 len=6
5 0.128 198.51.100.10:8001 > 192.0.2.10:53290 ·······A···· seq=1 ack=7 len=0
6 0.429 198.51.100.10:8001 > 192.0.2.10:53290 ·······A·R·· seq=1 ack=7 len=0
The server sent a reset (frame 6) instead of a FIN, and the client's pending recv() failed. This is a common source of mysterious "Connection reset by peer" errors in HTTP: a server that closes a connection right after sending a response, while the client's next request is already in its buffer. Linux counts these resets in the TCPAbortOnClose counter. nstat prints kernel counters as name, value since the last reset of the counters, and rate per second:
TcpExtTCPAbortOnData 0 0.0
TcpExtTCPAbortOnClose 1 0.0
Half-open connections
A connection is half-open when one side has lost all knowledge of it without the other side finding out. The usual cause is a crash, a reboot or a power cut on one host. The surviving host still thinks the connection is ESTABLISHED, and it will go on thinking so for as long as it sends nothing. (Article 71 shows how keepalives detect this.)
In the lab, the server "crashed": it discarded its socket without sending a FIN or a reset. (The lab used the TCP_REPAIR socket option, which lets a privileged program remove a connection silently.) The server's view right afterwards showed only its listening socket:
LISTEN 0 128 0.0.0.0:7000 0.0.0.0:*
The client still showed ESTAB. When it sent its next line, the server's TCP found no connection for it and replied with a reset:
client before sending: ESTAB
client: recv() failed: [Errno 104] Connection reset by peer
server: got b'foo\n'
server: connection state discarded without sending FIN or RST
1 0.000 192.0.2.10:57354 > 198.51.100.10:7000 ··········S· seq=0 ack=0 len=0
2 0.057 198.51.100.10:7000 > 192.0.2.10:57354 ·······A··S· seq=0 ack=1 len=0
3 0.057 192.0.2.10:57354 > 198.51.100.10:7000 ·······A···· seq=1 ack=1 len=0
4 0.057 192.0.2.10:57354 > 198.51.100.10:7000 ·······AP··· seq=1 ack=1 len=4
5 0.118 198.51.100.10:7000 > 192.0.2.10:57354 ·······A···· seq=1 ack=5 len=0
6 0.471 192.0.2.10:57354 > 198.51.100.10:7000 ·······AP··· seq=5 ack=1 len=4
7 0.529 198.51.100.10:7000 > 192.0.2.10:57354 ·········R·· seq=1 ack=0 len=0
The ladder diagram below draws the same exchange on a time axis, with the idle gap in which the server forgot the connection.

The reset's sequence number is 1 (relative), the ACK number of the client's data segment, following the rule from the first section. Resets like this are how a client learns that a server restarted while a connection was idle.
TIME-WAIT assassination
TIME-WAIT (article 61) waits out old segments. But what if an old segment arrives during TIME-WAIT and provokes a reset? RFC 1337 describes the problem, named TIME-WAIT assassination:
- The client is in TIME-WAIT. The server has finished and forgotten the connection.
- An old, delayed segment from the server arrives at the client.
- The client answers with an ACK carrying its current sequence numbers, as TCP does for any unacceptable segment.
- The server has no connection for that ACK and replies with a reset.
- The reset carries exactly the sequence number the client expects, so the client accepts it and drops its TIME-WAIT state early.
The lab reproduced this by sending a crafted old segment from the server's address (sequence number 100 bytes before the server's final one, ACK 200 bytes before the client's). Linux's behavior depends on net.ipv4.tcp_rfc1337. In the capture, the relative numbers seq=-98 ack=-198 are negative because they lie before the connection's final numbers (2 and 2): 2 − 100 = −98 and 2 − 200 = −198:
net.ipv4.tcp_rfc1337 = 0
before: 192.0.2.10:38562 198.51.100.10:6000 in TIME-WAIT
after the old segment: no TIME-WAIT socket
7 1.584 198.51.100.10:6000 > 192.0.2.10:38562 ·······AP··· seq=-98 ack=-198 len=8
8 1.584 192.0.2.10:38562 > 198.51.100.10:6000 ·······A···· seq=2 ack=2 len=0
9 1.636 198.51.100.10:6000 > 192.0.2.10:38562 ·········R·· seq=2 ack=0 len=0
The ladder below shows the three segments of the capture in order: the old segment, the client's ACK and the server's reset.

With the default of 0, the reset ended TIME-WAIT, which is the assassination. With tcp_rfc1337 = 1, the same sequence of segments left the TIME-WAIT socket in place:
net.ipv4.tcp_rfc1337 = 1
before: 192.0.2.10:38578 198.51.100.10:6000 in TIME-WAIT
after the old segment: 192.0.2.10:38578 198.51.100.10:6000 in TIME-WAIT
Linux keeps the default at 0. The risk is small, especially with timestamps and random ISNs, and some setups rely on resets to clear TIME-WAIT quickly.
Blind reset attacks and challenge ACKs
A reset ends a connection, so an attacker who can forge one can cut connections. To be accepted under the original rules, a reset needed only the right 4-tuple and a sequence number somewhere in the receive window. With a 64 KB window, a blind attacker who knows the addresses and ports has a 1 in 65,536 chance per guess (2³² possible sequence numbers ÷ 65,536 numbers in the window = 65,536), and a few tens of thousands of packets could break a long-lived connection such as a BGP session. (BGP sessions today are also protected by TCP-AO or the older MD5 option, article 60, which make forged resets fail authentication.)
RFC 5961 tightened the rules, and Linux follows them. The diagram places the possible resets on a sequence number line; the list after it gives the rules:

- An RST with a sequence number outside the window is dropped silently.
- An RST whose sequence number is exactly the next expected one (
RCV.NXT) resets the connection. - An RST elsewhere in the window gets a challenge ACK: an ACK with the receiver's real sequence numbers. If the reset came from the real peer, the peer answers with a reset carrying the exact number, and the connection ends. An attacker who can't see the traffic never sees the challenge ACK.
- A SYN on an established connection also gets a challenge ACK instead of resetting the connection, as RFC 793 used to require.
The lab sent four crafted segments from the server's address to an established connection:
(the client expects the server's next byte to have seq 1278031969)
RST with seq 1,000,000 away (outside the window):
client state: ESTAB
RST with seq 1000 bytes into the window:
client state: ESTAB
SYN on the established connection:
client state: ESTAB
RST with exactly the expected seq:
client state: (no socket)
client: recv() failed: [Errno 104] Connection reset by peer
The capture at the client, with raw sequence numbers:
6 1.187 198.51.100.10:5000 > 192.0.2.10:33800 ·········R·· seq=1279031969 ack=0 len=0
7 2.210 198.51.100.10:5000 > 192.0.2.10:33800 ·········R·· seq=1278032969 ack=0 len=0
8 2.210 192.0.2.10:33800 > 198.51.100.10:5000 ·······A···· seq=1738456601 ack=1278031969 len=0
9 3.318 198.51.100.10:5000 > 192.0.2.10:33800 ··········S· seq=12345 ack=0 len=0
10 3.318 192.0.2.10:33800 > 198.51.100.10:5000 ·······A···· seq=1738456601 ack=1278031969 len=0
11 4.378 198.51.100.10:5000 > 192.0.2.10:33800 ·········R·· seq=1278031969 ack=0 len=0
The out-of-window reset (frame 6) got no reply. The in-window reset (frame 7) and the SYN (frame 9) each got a challenge ACK (frames 8 and 10) acknowledging the expected sequence number. Only the reset with the exact number (frame 11) ended the connection. The kernel's counters:
TcpEstabResets 1 0.0
TcpExtTCPChallengeACK 2 0.0
TcpExtTCPSYNChallenge 1 0.0
Common questions
Is a reset always an error?
No. Some applications abort connections deliberately, and some load balancers and browsers reset idle connections to free resources. But a reset always means data may have been lost, so the application on the receiving side should treat the exchange as incomplete.
Why does "Connection reset by peer" sometimes appear after the response arrived?
Often because the peer closed with unread data in its receive buffer, which turns its FIN into a reset. Depending on the system and timing, the reset can also cost the receiver data: anything still in flight is lost, and some systems discard received data the application hasn't read yet.
Who sends resets besides the peer?
Firewalls with "reject with tcp reset" rules, intrusion prevention systems, and censorship systems that inject resets into connections they want to block. Injected resets often have a TTL or IP ID that doesn't match the peer's other segments.
Does TCP retransmit a reset?
No. A reset is never acknowledged and never retransmitted. If it's lost, the next segment from the other side will draw another reset.
What's the difference between "Connection refused" and "Connection reset"?
"Refused" (ECONNREFUSED) means a reset arrived in reply to the SYN, so the connection never opened. "Reset" (ECONNRESET) means it arrived on an established connection.
Should I turn on tcp_rfc1337?
It's harmless and protects TIME-WAIT from assassination, but the problem it solves is rare in practice. Most systems leave it at the default of 0.
Summary
- A reset ends a connection immediately, discards queued data, and is never acknowledged. Applications see "Connection refused" (during the handshake) or "Connection reset by peer".
- A SYN to a closed port gets a reset with sequence 0 and ACK = ISN + 1. Firewalls that reject send the same thing, while firewalls that drop leave the client waiting until it times out.
SO_LINGERwith timeout 0 aborts a connection with a reset. Closing a socket with unread received data also sends a reset.- After a crash, the surviving host keeps a half-open connection until it sends something and gets a reset.
- An old segment arriving during TIME-WAIT can provoke a reset that ends TIME-WAIT early.
tcp_rfc1337 = 1makes Linux ignore resets in TIME-WAIT. - Under RFC 5961, only a reset with exactly the expected sequence number is accepted. In-window resets and SYNs get a challenge ACK, and out-of-window resets are dropped.
Practice questions
1. A SYN with sequence number 1,000,000 arrives at a port with no listener. What are the sequence number, ACK number and flags of the reset?
Answer
Sequence number 0, ACK number 1,000,001 (the SYN occupies one sequence number), and flags RST and ACK. The SYN had no ACK, so the reset can't take its sequence number from one.
2. An internal service blocks a port with a firewall rule, and clients hang for two minutes before failing. What's probably happening, and what would make them fail fast?
Answer
The rule drops SYNs, so clients keep retransmitting until connect() times out (about 2 minutes on Linux). Changing the rule to reject with a TCP reset makes connect() fail with "Connection refused" in one round trip.
3. A web server sends a response and immediately calls close(), but the client has already sent its next request on the same connection. What does the client see, and why?
Answer
The server closes with unread data (the next request) in its receive buffer, so its TCP sends a reset instead of a FIN. The client gets "Connection reset by peer" on its next read or write, and may lose part of the response if it was still in flight or, on some systems, still unread in the client's buffer.
4. A server reboots while a client has an idle SSH connection to it. When does the client find out, and how?
Answer
Only when it sends something: a keystroke, or a keepalive probe if keepalives are on. The rebooted server has no record of the connection and replies with a reset, and the client's SSH reports that the connection was reset. If nothing is sent, the client never finds out.
5. An attacker sends an RST with the right addresses and ports and a sequence number 5,000 bytes inside the receive window of a Linux connection. What happens?
Answer
The connection survives. The receiver sends a challenge ACK with its real sequence numbers. Only the real peer would see it and respond with an exact-sequence reset, and if the peer didn't send the original RST, it simply treats the ACK as a duplicate.
6. In the TIME-WAIT assassination lab, why did the reset carry exactly the sequence number the client expected?
Answer
The reset was a reply to the client's ACK, which carried the client's current ACK number L (the server's next sequence number). A reset sent in reply to a segment with an ACK uses that ACK number as its sequence number, so it was exactly L, which the client accepts.
Previous: The TCP State Machine and TIME_WAIT
Next: TCP Servers: Listening Sockets, Binding, the Accept Queue, SYN Cookies and SYN Floods

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.