What the Message Means
A TCP connection normally ends with a FIN packet from each side: a polite close. A reset (RST) packet ends it at once, and any data still in flight is lost. When a program on Linux receives a reset, the system call fails with error 104, ECONNRESET, and the program prints "Connection reset by peer". The peer is whatever sent the packet, which can be a device between the two ends.
Where You See It
- curl:
curl: (56) Recv failure: Connection reset by peer, or an error during the TLS handshake. - SSH: a line ending in
read: Connection reset by peerwhile logging in, or a "Connection reset" message that ends a session. - Nginx error log:
recv() failed (104: Connection reset by peer)while reading from the upstream; the visitor gets a 502. - Applications:
ECONNRESETin Node.js,ConnectionResetErrorin Python. - Browsers: Chrome shows ERR_CONNECTION_RESET.
Common Causes
| Cause | Typical clue |
|---|---|
| Service crashed or restarted | Errors at one moment; restart in the log |
| Firewall rejects with a reset | Every attempt fails at once |
| Idle timeout on NAT or a load balancer | Long idle connections fail on next use |
| Backend closed a keepalive connection | Rare errors, even under light load |
| Connection limit reached | Errors grow with traffic |
The Causes in More Detail
- Crash or restart: open connections die with the process. Check
journalctl -u servicefor restarts, and the kernel log for an OOM killer entry. - Firewall: a rule such as iptables
REJECT --reject-with tcp-reset, or a Fail2ban ban that uses it, answers with a reset. - Idle timeouts: a NAT device or load balancer forgets a connection that was quiet for too long, and answers the next packet with a reset. TCP keepalives or application pings shorter than that timeout keep the entry alive. For SSH, see SSH broken pipe.
- Keepalive race: a proxy reuses an idle connection at the same moment the backend closes it. Keep the backend's idle timeout longer than the proxy's.
- Limits: a worker limit or the open-file limit (ulimit) can make a service close connections at once. A full listen queue usually makes Linux drop new connections silently, which looks like a timeout; it sends resets only when
net.ipv4.tcp_abort_on_overflowis set to 1.
Find Which Side Sends the Reset
Capture reset packets on the server while you reproduce the error:
sudo tcpdump -ni any 'tcp[tcpflags] & tcp-rst != 0 and port 443'
The source address of each packet shows who sent it. Run the same capture on the client. If the client receives a reset that the server never sent, a device in between sent it. The tcpdump command guide explains the filters.
Check Sockets and Counters
ss -s
ss -tanp | grep ':8080'
nstat -az | grep -i -E 'rst|reset'
ss -s summarizes sockets by state, the second line lists connections on one port with their processes, and nstat shows the kernel's reset counters. Run nstat before and after a burst of errors and compare. Details are in the ss command guide.
Read the Logs on Both Ends
The client log tells you when it happened; the server log tells you why. Match the timestamps: a restart, a worker that hit a limit, or a timeout message at the same second is usually the answer. If the server log shows nothing at that moment, look at the devices in between.
Quick Tests
curl -v https://example.com/
nc -vz 203.0.113.10 8080
openssl s_client -connect example.com:443 -servername example.com
A reset right after connect points to a firewall or a service that refuses the client. A reset during the TLS handshake points to the TLS settings. A reset after a long idle period points to a timeout in between.