What does "connection reset by peer" mean?
Codemia Knowledge Hub ·
"Connection reset by peer" means the remote side of a TCP connection closed it abruptly by sending a RST (reset) packet instead of going through the normal TCP shutdown. The server (or client) on the other end forcibly terminated the connection, so your application got an error instead of the data it expected.
Normal close vs. reset
A graceful TCP close is a four-step FIN handshake:
- Side A sends a FIN packet ("I'm done sending")
- Side B acknowledges the FIN
- Side B sends its own FIN ("I'm done too")
- Side A acknowledges
That lets both sides finish processing remaining data. A reset skips all of it: the peer sends one RST packet that says "this connection no longer exists, stop immediately."
What triggers a RST packet
At the TCP level, a RST is sent in these situations:
Here is how it surfaces in application code.
Python:
Java:
curl:
Causes and how to confirm each
| Cause | Symptoms | How to Confirm |
| Server crashed or restarted | Sudden reset during active request | Check server uptime logs, look for OOM kills |
| Server-side timeout | Reset after idle period | Compare idle time against server's keepalive_timeout |
| Load balancer dropped connection | Intermittent resets under load | Check LB idle timeout settings (often 60s on AWS ALB) |
| Firewall or IDS killed connection | Resets on specific request patterns | Packet capture shows RST from intermediate IP |
| Server rejected TLS handshake | Reset during SSL negotiation | openssl s_client -connect host:port fails |
| Server's listen backlog full | Slow or timed-out connects during a spike; resets only if net.ipv4.tcp_abort_on_overflow=1 (Linux drops the SYN by default) | netstat -s shows listen queue overflows |
| Client sent data after server closed | Reset on write after partial read | Application logs show incomplete reads |
Debugging a reset step by step
Step 1: Capture the packets
Looking at the actual packets is the most reliable diagnosis:
Find the RST and check what came right before it. That preceding packet usually tells you the cause.
Step 2: Check server-side logs
Step 3: Check connection limits and timeouts
Step 4: Test with different tools
Handling resets in your code
The right response depends on whether the operation is idempotent (safe to retry).
Python with retry logic:
Node.js with retry:
Reset vs. refused, timed out and broken pipe
| Error | What It Means | TCP Behavior |
| Connection reset by peer | Remote side sent RST | Abrupt close, no FIN handshake |
| Connection refused | No process listening on port | RST in response to SYN |
| Connection timed out | No response at all | No packets received |
| Broken pipe | Write to a closed connection | Local side detects closed socket |
| EOF / Connection closed | Remote side sent FIN | Graceful close |
The fix differs for each. "Connection refused" means the service is not running. "Connection reset" means it was running but dropped you.
Mistakes that make resets worse
- Retrying non-idempotent requests. If a POST is reset, the server may already have processed it, and a blind retry can create duplicates. Only retry idempotent operations (GET, PUT, DELETE) automatically.
- Ignoring keep-alive mismatches. If the client holds a connection for 120 seconds but the server's keep-alive timeout is 60, the server closes it and your next request on it gets a reset. Keep client timeouts shorter than server timeouts.
- Blaming the network for an application problem. A reset at the same point every time (for example, after a specific header or payload) usually means the server is rejecting the request.
- Skipping intermediate proxies. Load balancers, CDNs and reverse proxies have their own idle timeouts. An AWS ALB defaults to a 60-second idle timeout; if the backend takes longer to respond, the ALB returns
504 Gateway Timeoutto the client rather than a reset, and it closes client connections that sit idle past the timeout. Check every hop's timeout, not just the server's.
Related reading
- What does exited with code 9009 mean during this build?
- What does Fatal error Unexpectedly found nil while unwrapping an Optional value mean?
- What does get-task-allow do in Xcode?
- What does is unavailable Use truncatingRemainder instead mean?
- What does it mean The serializable class does not declare a static final serialVersionUID field?
- What does it mean when MySQL is in the state Sending data?
- What does MissingManifestResourceException mean and how to fix it?
- What does mysql error 1025 HY000 Error on rename of './foo' errorno 150 mean?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.