What does connection reset by peer mean?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
"Connection reset by peer" means the remote side of a TCP connection abruptly closed the connection by sending a RST (reset) packet instead of going through the normal TCP shutdown sequence. In practical terms, the server (or client) on the other end forcibly terminated the connection, and your application received an error instead of the data it expected.
How TCP Connections Normally Close
To understand a reset, you first need to understand a normal close. TCP connections terminate gracefully with 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
This orderly shutdown lets both sides finish processing any remaining data. A connection reset skips all of this. The peer sends a single RST packet that says "this connection no longer exists, stop immediately."
What Triggers a RST Packet
At the TCP level, a RST packet is sent in these situations:
Here is what these look like in application code:
Python:
Java:
curl:
Common Causes and How to Identify Them
| 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 | Reset on new connections during spike | netstat -s shows listen queue overflows |
| Client sent data after server closed | Reset on write after partial read | Application logs show incomplete reads |
Debugging Step by Step
Step 1: Capture the packets
The most reliable way to diagnose a connection reset is to look at the actual packets:
Look for the RST packet and check what came immediately before it. The packet before the RST usually tells you the cause.
Step 2: Check server-side logs
Step 3: Check connection limits and timeouts
Step 4: Test with different tools
How to Handle Connection 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:
Connection Reset vs. Other Network Errors
| 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 |
Understanding these distinctions matters because the fix is different for each. A "connection refused" means the service is not running. A "connection reset" means it was running but dropped you.
Common Pitfalls
- Retrying non-idempotent requests. If a POST request gets reset, the server may have already processed it. Blindly retrying could create duplicate records. Only retry idempotent operations (GET, PUT, DELETE) automatically.
- Ignoring keep-alive mismatches. If your client holds a connection open for 120 seconds but the server's keep-alive timeout is 60 seconds, the server will close the connection and your next request on that connection gets a reset. Set client timeouts to be shorter than server timeouts.
- Blaming the network when it's the application. A reset that consistently happens at the same point in a request (e.g., after sending a specific header or payload) usually indicates the server is rejecting the request, not a network problem.
- Not checking intermediate proxies. Load balancers, CDNs, and reverse proxies all have their own idle timeout settings. An AWS ALB defaults to 60 seconds, and if your backend takes longer, the ALB resets the client connection.
Summary
- "Connection reset by peer" means the remote side sent a TCP RST packet, forcibly closing the connection.
- Common causes include server restarts, load balancer timeouts, firewall rules, and listen queue overflows.
- Use
tcpdumpor Wireshark to capture packets and identify the exact cause from the packet preceding the RST. - Implement retry logic with exponential backoff for idempotent operations.
- Distinguish between connection resets, refused connections, timeouts, and broken pipes, because the fix is different for each.
- Check intermediate infrastructure (load balancers, CDNs, proxies) for timeout mismatches, not just the origin server.

