Connection reset by peer: meaning and how to fix it

Connection reset by peer means a TCP RST killed the connection. We reproduced each cause on Kubernetes with packet captures and exact client errors.

Ben Gervais
Ben Gervais, Engineer at Arvo AILinkedInGitHub
Applies toAny TCP client on Linux; shown on Kubernetes with pods talking through a ClusterIP Service, and on SSH in plain Docker. Cloud load balancers and service meshes were not tested
Verified onKubernetes server v1.37.0, kind v0.33.0, kubectl client v1.37.2, kernel 7.0.0-1017-azure, Alpine 3.22.8, curl 8.14.1, Python 3.12.16 with requests 2.33.1 and urllib3 1.26.20, Go 1.25.14, Node v22.23.4, tcpdump 4.99.5, OpenSSH 10.0p2, 2026-11-05
Lab folderscenarios/24-connection-reset-by-peer, transcripts in runs/search-2026-11-05/24-connection-reset-by-peer

"Connection reset by peer" means the other end of a TCP connection, or a device between you and it, sent a RST segment, and your kernel aborted the connection. It is an established connection being killed, not a refused one, and it does not prove the remote application crashed. On Kubernetes we reproduced it from a pod killed during a rollout with no drain, a keepalive connection closed as the client reused it, a process exiting with unread bytes or queued connections, and a firewall rule. A packet capture separates them: tcpdump -nn 'tcp[tcpflags] & tcp-rst != 0' on the client shows the RST, and what came just before it names the cause.

Our main result is that many failures that look like a reset are not one. A process that dies after reading the whole request sends a FIN, and curl prints Empty reply from server. The string in your log narrows down which packet arrived, but it does not prove it: Go and Python each printed the same error for a FIN and for a RST in our tests. Read the string exactly, then confirm with a capture before you change anything.

At a glance: which cause is it?

Every row was reproduced. The order follows the investigation, not how common each cause is in production: we have no data on that.

Client saysOn the wireLikely causeConfirm withFix
Connection reset by peer, curl: (56), read ECONNRESET, Go's use of closed network connection during a deployRST with no FIN before itPod exited with unread bytes (an upload, say)Error times match kubectl rollout history; RST in a capturepreStop delay plus draining on SIGTERM
Same, under load on a single-threaded or blocked serverRST on connections with a request sent and only an ACK backProcess died with connections in its accept queueSeveral clients reset at the same instant; restart in kubectl get podsFix the crash; drain
Same, a low rate at idle-timeout boundaries, no deployRequest, then RST at once, with the request bytes acknowledgedServer closed an idle connection as the request landedTime since the last request on that connection equals the server's idle timeoutClient idle timeout below the server's; retry idempotent requests
Broken pipe, EPIPEUsually FIN, then your write, then RST. Sometimes a RST aloneYou wrote to a connection already deadWhether a FIN precedes the RST in a captureDepends on which: keepalive race or no drain, above and below
Empty reply from server, EOF, socket hang up, Python's RemoteDisconnected (which also hid a RST on uploads)FIN, no responseProcess exited or closed after reading the requestkubectl get pods restarts, lastState, the app logFix the crash. See 502 Bad Gateway if a proxy is in front
curl: (18) end of response with ... bytes missing, unexpected EOFFIN part way through the bodyProcess exited while sending the responseContent-Length larger than bytes receivedDrain on SIGTERM
Connection reset by peer, server healthy, server has no record of the requestRST with a different TTL from the SYN-ACK; server capture shows no requestFirewall, proxy or load balancer in the pathCapture at both endsFix that device's rule or idle timeout
connection refused, Could not connect to serverSYN answered by RST, or ICMP port unreachableNothing listening, or no endpointskubectl get endpointslicesService has no endpoints

What does connection reset by peer mean?

A TCP connection ends in one of two ways. A FIN is an orderly close: "I have finished sending." Data already in flight still arrives, and the other side reads end of file. A RST is an abort: the receiver aborts the connection and tells the application, and on Linux the application gets ECONNRESET, whose text is "Connection reset by peer".

"Peer" means whoever sent that packet with the right addresses, which is not always the machine you think it is. A healthy close from our baseline, client side, ends with FINs from both ends:

    10.244.2.13.33896 > 10.96.132.149.8080: Flags [F.], cksum 0x9c1c (incorrect -> 0x405c), seq 85, ack 120, win 63, options [nop,nop,TS val 619660701 ecr 2332231472], length 0
    10.96.132.149.8080 > 10.244.2.13.33896: Flags [F.], cksum 0x9c1c (incorrect -> 0x405a), seq 120, ack 86, win 64, options [nop,nop,TS val 2332231472 ecr 619660701], length 0
    10.244.2.13.33896 > 10.96.132.149.8080: Flags [.], cksum 0x9c1c (incorrect -> 0x405b), ack 121, win 63, options [nop,nop,TS val 619660701 ecr 2332231472], length 0

(tcpdump -nn -p -i eth0 -tttt -v in the client pod, IP header lines removed here and in the other captures unless shown, last three packets.)

Linux sends a RST in three situations we hit: a segment arrives for a connection that no longer exists, a socket is closed with received bytes still unread (data_was_unread in __tcp_close), or a listening socket closes with connections still in its queue. The second one is why a dead process sometimes gives a FIN and sometimes a RST.

Connection reset by peer vs connection refused vs broken pipe

The kernel picks the error from the socket state when the RST arrives, in the switch in tcp_reset: SYN_SENT gives ECONNREFUSED, CLOSE_WAIT gives EPIPE, and an open connection gets ECONNRESET. So:

  • Connection refused: the RST answered your SYN. No connection existed.
  • Connection reset by peer: the RST hit an established connection with no FIN before it.
  • Broken pipe: you wrote to a dead connection. Normally a FIN came first, then you wrote, then the RST came back.

Broken pipe does not prove a FIN, though. The kernel hands a pending socket error to one call only (sock_error clears it), and later writes on the dead socket get EPIPE. In one run of our upload crash test, Go printed write: broken pipe on a connection that received only a RST, with no FIN in the capture. Go reads and writes in separate goroutines, so the likely explanation is that the read took the ECONNRESET.

Nothing listening on a port of the server pod, four clients:

curl: (7) Failed to connect to 10.244.1.23 port 9 after 0 ms: Could not connect to server
python requests error: requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.244.1.23', port=9): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7efc444cc920>: Failed to establish a new connection: [Errno 111] Connection refused'))
go net/http error: Get "http://10.244.1.23:9/": dial tcp 10.244.1.23:9: connect: connection refused
node error: code=ECONNREFUSED message=connect ECONNREFUSED 10.244.1.23:9

With -sS, curl 8.14.1 does not print the words "Connection refused", so a search for them in that output finds nothing. The capture of the first attempt:

    10.244.2.13.48784 > 10.244.1.23.9: Flags [S], cksum 0x193a (incorrect -> 0xe934), seq 703332923, win 64240, options [mss 1460,sackOK,TS val 1196234942 ecr 0,nop,wscale 10], length 0
    10.244.1.23.9 > 10.244.2.13.48784: Flags [R.], cksum 0xac03 (correct), seq 0, ack 703332924, win 0, length 0

A ClusterIP with no endpoints looks the same to the client but different on the wire. The client's own node answers with ICMP, from kube-proxy's reject rule, and no RST exists:

    10.244.2.1 > 10.244.2.13: ICMP 10.96.227.193 tcp port 8080 unreachable, length 68

How do you confirm it and see the RST?

Capture on the client side, because the client survives the failure and the server may not. We ran tcpdump inside the client pod. Our image includes it and the pod has NET_RAW. Our script's filter also listed ports 8081 and 2222 and ICMP:

tcpdump -l -nn -p -i eth0 -tttt -v 'tcp port 8080'

To print only resets on a real pod, use an ephemeral debug container. We did not run this exact form; it shares the pod's network namespace the same way as our sidecar did. An ephemeral container stays in the pod spec until the pod is replaced, and restricted clusters may refuse it:

kubectl debug -it <pod> --image=nicolaka/netshoot --target=<container> -- tcpdump -nn -i any 'tcp[tcpflags] & tcp-rst != 0'

Flags [R] or Flags [R.] is a reset, Flags [F.] is a FIN, and Flags [S] is a SYN. Then read three things: did a FIN come before the RST, what did the client do just before it, and is the TTL the same as on the SYN-ACK.

How much is affected, and since when?

Compare the first error with your change log. In the rollout test below, kubectl rollout restart ran at 00:03:55.21 and the RST reached the client at 2026-11-06 00:03:55.927544, so the timestamps alone point at the deploy. If errors occur with no rollout, check restarts next. Our OOM test left this, from .status.containerStatuses, with restart count, reason and exit code:

1 OOMKilled 137

In the shop scenario every pod was Running and Ready after the deploy, with zero restarts, and the rollout reported success. The only evidence of failure was on the client, so look there first.

Pod killed mid-request during a rollout, with no drain

The test server is a Go process with no SIGTERM handling, so it exits at once. We started four uploads paced at 1 MiB/s, two slow GETs and two streaming downloads, then ran kubectl -n rst rollout restart deploy/srv. In the first variant the handler read 64 KiB every 100 ms, slower than the clients send, leaving unread bytes in the socket buffer:

curl: (56) Recv failure: Connection reset by peer
node error: code=ECONNRESET message=read ECONNRESET
go net/http error: Post "http://10.96.132.149:8080/upload": write tcp 10.244.2.13:52686->10.96.132.149:8080: use of closed network connection
python requests error: requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
curl: (52) Empty reply from server
curl: (18) end of response with 1072988160 bytes missing
go net/http status: 200 body bytes: 753664 body read error: unexpected EOF

(From 03-rollout-slowreader.txt. The Python line is its upload. The curl: (52) line is a slow GET, and the last two are the streams.)

Of the eight connections, the four uploads ended in a RST and the other four in a FIN. Go's upload, port 52686, got the RST with no FIN before it; Go's stream, port 52672, got a FIN:

    10.96.132.149.8080 > 10.244.2.13.52686: Flags [R.], cksum 0x9c1c (incorrect -> 0xab4a), seq 1, ack 2532975, win 612, options [nop,nop,TS val 944280883 ecr 3195585540], length 0
    10.96.132.149.8080 > 10.244.2.13.52672: Flags [F.], cksum 0x9c1c (incorrect -> 0xd66a), seq 753789, ack 106, win 64, options [nop,nop,TS val 3862289025 ecr 1407310885], length 0

The HTTP headers in the capture tie each flow to its client. Go reported its RST as use of closed network connection. The same client printed write: connection reset by peer in the upload crash test (07b-crash-upload.txt) and write: broken pipe on that test in the earlier run, also on a RST with no FIN. Python's upload, port 52724, also got a RST with no FIN and printed RemoteDisconnected, in this test and in the crash test. That fits urllib3 1.26.20, which swallows ECONNRESET while sending and then reads for a response. So RemoteDisconnected on an upload says nothing about FIN or RST.

Then we repeated it with one change, a server that reads as fast as the clients send, so nothing is unread when it dies:

curl: (52) Empty reply from server
node error: code=ECONNRESET message=socket hang up
go net/http error: Post "http://10.96.132.149:8080/upload?fast=1": write tcp 10.244.2.13:45612->10.96.132.149:8080: use of closed network connection

Same rollout and same curl command, and curl went from a reset to an empty reply. All eight connections got a FIN, and Go and Python printed the same strings as they did for a RST. Node's socket hang up carries code=ECONNRESET even though no RST caused it, so in Node, ECONNRESET alone does not prove a reset: read the message, read ECONNRESET or socket hang up. Only Python's upload saw a RST here, and only after the FIN, when it wrote again:

    10.96.132.149.8080 > 10.244.2.13.45664: Flags [F.], cksum 0x9c1c (incorrect -> 0x2c83), seq 1, ack 5505405, win 1106, options [nop,nop,TS val 2716804784 ecr 3241942668], length 0
    10.96.132.149.8080 > 10.244.2.13.45664: Flags [R], cksum 0x27a7 (correct), seq 3680124664, win 0, length 0
    10.96.132.149.8080 > 10.244.2.13.45664: Flags [R], cksum 0x27a7 (correct), seq 3680124664, win 0, length 0
    10.96.132.149.8080 > 10.244.2.13.45664: Flags [R], cksum 0x27a7 (correct), seq 3680124664, win 0, length 0

Keepalive race: the server closes an idle connection as the client writes to it

The test server has IdleTimeout of 2 seconds. A client with no pool checks wrote 3 seconds after its last response:

$ python3 /app/raw_idle.py 10.96.132.149 8080 3
first response: b'HTTP/1.1 200 OK'
write after idle -> 29
second write -> BrokenPipeError: [Errno 32] Broken pipe
third write -> BrokenPipeError: [Errno 32] Broken pipe
read -> b''
    10.96.132.149.8080 > 10.244.2.13.55902: Flags [F.], cksum 0x9c1c (incorrect -> 0x3b5e), seq 120, ack 30, win 64, options [nop,nop,TS val 946282153 ecr 2678389837], length 0
    10.244.2.13.55902 > 10.96.132.149.8080: Flags [.], cksum 0x9c1c (incorrect -> 0x3365), ack 121, win 63, options [nop,nop,TS val 2678391879 ecr 946282153], length 0
    10.244.2.13.55902 > 10.96.132.149.8080: Flags [P.], cksum 0x9c39 (incorrect -> 0x705d), seq 30:59, ack 121, win 63, options [nop,nop,TS val 2678392837 ecr 946282153], length 29: HTTP, length: 29
    10.96.132.149.8080 > 10.244.2.13.55902: Flags [R], cksum 0xe470 (correct), seq 3279974922, win 0, length 0

The first write succeeds, because the kernel accepts it locally. The RST comes back, and because a FIN arrived first, the client gets BrokenPipeError on the next write and end of file on read. It never gets a reset. On Linux, writing to a connection the peer has already closed gives broken pipe, not reset by peer.

Real clients notice a FIN on an idle connection and open a new one, so the failure needs the request and the close to cross. We aimed at that window: 50 connections, 60 rounds each, reusing the connection at 2 s plus or minus 5 ms, with POST so Go would not replay it.

$ rstclient sweep -X POST -idle 2s -window 5ms -c 50 -n 60 http://10.96.132.149:8080/ok
summary:
  1464  reused=false ok
   133  reused=true error: Post "http://<addr>/ok": EOF
    18  reused=true error: Post "http://<addr>/ok": http: server closed idle connection
    17  reused=true error: Post "http://<addr>/ok": read tcp <addr>-><addr>: read: connection reset by peer
  1368  reused=true ok

That is 168 failures in 3,000 tries, and 119 in 3,000 in the earlier run (95 EOF, 8 idle, 16 reset). The window was aimed on purpose, so this rate says nothing about production. What matters is the split: on Go, only about one race in ten surfaces as a reset (17 of 168 and 16 of 119, two runs). Python's requests.Session over 1,200 tries gave 7 ConnectionResetError and 8 RemoteDisconnected, then 2 and 18 in the earlier run, so the split varies by client and by run.

The capture shows why the two differ. The EOF case: a FIN crossed the request and the RST followed.

FAIL local=10.244.2.13:44904 offset=294.114µs reused=true err=Post "http://10.96.132.149:8080/ok": EOF
    10.244.2.13.44904 > 10.96.132.149.8080: Flags [P.], cksum 0x9c96 (incorrect -> 0x1413), seq 123:245, ack 120, win 63, options [nop,nop,TS val 4183679888 ecr 4201999254], length 122: HTTP, length: 122
    10.96.132.149.8080 > 10.244.2.13.44904: Flags [F.], cksum 0x9c1c (incorrect -> 0x8e2c), seq 120, ack 123, win 64, options [nop,nop,TS val 4202001254 ecr 4183677888], length 0
    10.96.132.149.8080 > 10.244.2.13.44904: Flags [R], cksum 0xf17c (correct), seq 2020137740, win 0, length 0

The reset case has no FIN at all. The server's ACK number, 245, covers the request: the bytes reached the server's socket before it closed, so it closed with unread data and sent a RST.

FAIL local=10.244.2.13:41748 offset=-540.747µs reused=true err=Post "http://10.96.132.149:8080/ok": read tcp 10.244.2.13:41748->10.96.132.149:8080: read: connection reset by peer
    10.244.2.13.41748 > 10.96.132.149.8080: Flags [P.], cksum 0x9c96 (incorrect -> 0x54cb), seq 123:245, ack 120, win 63, options [nop,nop,TS val 3142802019 ecr 4124342598], length 122: HTTP, length: 122
    10.96.132.149.8080 > 10.244.2.13.41748: Flags [R.], cksum 0x9c1c (incorrect -> 0xc697), seq 120, ack 245, win 64, options [nop,nop,TS val 4124344598 ecr 3142802019], length 0

Process exits or crashes with a request in flight

The handler reads the whole request, then calls os.Exit(1) without responding:

curl: (52) Empty reply from server
python requests error: requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
go net/http error: Get "http://10.96.132.149:8080/crash": EOF
node error: code=ECONNRESET message=socket hang up

All four connections ended in FINs, with no RST on the wire, despite Node's code=ECONNRESET. The curl one:

    10.244.2.13.42850 > 10.96.132.149.8080: Flags [S], cksum 0x9c24 (incorrect -> 0xbcb7), seq 3614442996, win 64240, options [mss 1460,sackOK,TS val 1840177752 ecr 0,nop,wscale 10], length 0
    10.96.132.149.8080 > 10.244.2.13.42850: Flags [S.], cksum 0x9c24 (incorrect -> 0x8ebf), seq 2490759032, ack 3614442997, win 65160, options [mss 1460,sackOK,TS val 3526413359 ecr 1840177752,nop,wscale 10], length 0
    10.244.2.13.42850 > 10.96.132.149.8080: Flags [.], cksum 0x9c1c (incorrect -> 0xbbd8), ack 1, win 63, options [nop,nop,TS val 1840177752 ecr 3526413359], length 0
    10.244.2.13.42850 > 10.96.132.149.8080: Flags [P.], cksum 0x9c73 (incorrect -> 0xa4c7), seq 1:88, ack 1, win 63, options [nop,nop,TS val 1840177752 ecr 3526413359], length 87: HTTP, length: 87
    10.96.132.149.8080 > 10.244.2.13.42850: Flags [.], cksum 0x9c1c (incorrect -> 0xbb80), ack 88, win 64, options [nop,nop,TS val 3526413359 ecr 1840177752], length 0
    10.96.132.149.8080 > 10.244.2.13.42850: Flags [F.], cksum 0x9c1c (incorrect -> 0xb989), seq 1, ack 88, win 64, options [nop,nop,TS val 3526413861 ecr 1840177752], length 0
    10.244.2.13.42850 > 10.96.132.149.8080: Flags [F.], cksum 0x9c1c (incorrect -> 0xb793), seq 88, ack 2, win 63, options [nop,nop,TS val 1840178254 ecr 3526413861], length 0
    10.96.132.149.8080 > 10.244.2.13.42850: Flags [.], cksum 0x9c1c (incorrect -> 0xb792), ack 89, win 64, options [nop,nop,TS val 3526413861 ecr 1840178254], length 0

This is the case scenario 20 covers behind nginx, where it appears as upstream prematurely closed connection. If nginx logs recv() failed (104: Connection reset by peer), the same page has that line and its causes.

The picture changes on a single-threaded server. A Python HTTPServer, one request in its handler and four more waiting unaccepted in the kernel queue, then the process exits:

curl: (52) Empty reply from server
curl: (56) Recv failure: Connection reset by peer
python requests error: requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
go net/http error: Get "http://10.96.132.149:8081/ok": read tcp 10.244.2.13:52414->10.96.132.149:8081: read: connection reset by peer
node error: code=ECONNRESET message=read ECONNRESET

The request in the handler got a FIN. All four queued clients got a RST within 100 microseconds:

    10.96.132.149.8081 > 10.244.2.13.52404: Flags [F.], cksum 0x9c1c (incorrect -> 0xdc04), seq 1, ack 94, win 64, options [nop,nop,TS val 1724680049 ecr 2584576026], length 0
    10.96.132.149.8081 > 10.244.2.13.52414: Flags [R.], cksum 0x9c1c (incorrect -> 0x9821), seq 1, ack 102, win 64, options [nop,nop,TS val 3330017805 ecr 931908199], length 0
    10.96.132.149.8081 > 10.244.2.13.52426: Flags [R.], cksum 0x9c1c (incorrect -> 0x1536), seq 1, ack 85, win 64, options [nop,nop,TS val 4243709535 ecr 3574863018], length 0
    10.96.132.149.8081 > 10.244.2.13.52436: Flags [R.], cksum 0x9c1c (incorrect -> 0x3a8f), seq 1, ack 71, win 64, options [nop,nop,TS val 1350323725 ecr 897562839], length 0
    10.96.132.149.8081 > 10.244.2.13.52450: Flags [R.], cksum 0x9c1c (incorrect -> 0xdc98), seq 1, ack 152, win 64, options [nop,nop,TS val 3030595169 ecr 1464231484], length 0

The queued clients had a completed handshake and an ACK for their request, and no process ever read it. A blocking worker that stalls before dying will do this to everything in its queue. An OOM kill behaves the same way: with a GET in its handler and an upload running, the kernel killed the container (OOMKilled, exit code 137), the upload got curl: (56) Recv failure: Connection reset by peer and the GET got curl: (52) Empty reply from server. For the memory side, see OOMKilled.

Closing with unread data does not need a dying process. A handler that answers 413 from the headers and closes without reading the body produced a RST in the capture, but our clients mostly survived it:

too large
413
python requests status: 413 too large
go net/http status: 413 body bytes: 10 body read error: <nil>
node error: code=EPIPE message=write EPIPE
node response error: code=ECONNRESET message=aborted

curl, Python and Go read the 413; Node got EPIPE and then aborted. Python's server half-closes first, the first step of the staged close RFC 9112 describes to avoid losing the response, so this outcome is specific to that server.

How do you tell a firewall or proxy from the server?

Capture at both ends and compare TTLs. We added this rule on the client's node, in the lab only, which resets the first data segment and leaves the server untouched:

iptables -I FORWARD -s <client-ip> -p tcp --dport 8080 --tcp-flags PSH PSH -j REJECT --reject-with tcp-reset

The clients print exactly what they print for a real server reset:

curl: (56) Recv failure: Connection reset by peer
python requests error: requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
go net/http error: Get "http://10.96.132.149:8080/ok": read tcp 10.244.2.13:37650->10.96.132.149:8080: read: connection reset by peer

The client capture gives it away. The SYN-ACK from the real server has ttl 62, two hops of routing. The RST claims the same address and has ttl 64:

2026-11-06 00:21:28.023390 IP (tos 0x0, ttl 62, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    10.96.132.149.8080 > 10.244.2.13.37632: Flags [S.], cksum 0x9c24 (incorrect -> 0x439a), seq 1286447158, ack 3618575577, win 65160, options [mss 1460,sackOK,TS val 1120216937 ecr 1593250993,nop,wscale 10], length 0
2026-11-06 00:21:28.023456 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 40)
    10.96.132.149.8080 > 10.244.2.13.37632: Flags [R], cksum 0x9c10 (incorrect -> 0x7475), seq 1286447159, win 0, length 0

The server's capture of that connection has the handshake and nothing else: no request and no RST.

    10.244.2.13.37632 > 10.244.1.68.8080: Flags [S], cksum 0x1967 (incorrect -> 0x2113), seq 3618575576, win 64240, options [mss 1460,sackOK,TS val 1593250993 ecr 0,nop,wscale 10], length 0
    10.244.1.68.8080 > 10.244.2.13.37632: Flags [S.], cksum 0x1967 (incorrect -> 0xc657), seq 1286447158, ack 3618575577, win 65160, options [mss 1460,sackOK,TS val 1120216937 ecr 1593250993,nop,wscale 10], length 0
    10.244.2.13.37632 > 10.244.1.68.8080: Flags [.], cksum 0x195f (incorrect -> 0xf370), ack 1, win 63, options [nop,nop,TS val 1593250993 ecr 1120216937], length 0

If the server never sent it, stop reading application code. Note that TTL only helps when the device is a different number of hops away or starts from a different TTL, and a proxy that terminates TCP is your real peer anyway, so capture on each side of it.

What is the fix?

Rollouts: delay shutdown, then drain. Pod termination and endpoint removal happen at the same time, so a pod can receive traffic after SIGTERM. You need both a delay and a drain:

kubectl -n rst patch deploy srv -p '{"spec":{"template":{"spec":{"containers":[{"name":"srv","lifecycle":{"preStop":{"sleep":{"seconds":5}}}}]}}}}'

This triggers a rollout, and every later rollout takes the delay longer per pod. Rollback is kubectl rollout undo. The sleep action is stable since Kubernetes 1.34; on older clusters use an exec hook, which needs a sleep binary in the image. The grace period covers the hook and the shutdown together, so set terminationGracePeriodSeconds above the delay plus your longest request. The app side, in our test server, is Go's signal.Notify for SIGTERM and srv.Shutdown(ctx).

We ran three rollouts of three replicas under steady load, eight workers on new connections and eight on keepalive, with a 200 ms POST and no retries in our client. Two runs of each, errors per client type:

ConfigRunNew connections: EOF / refused / resetKeepalive: EOF / refused / resetOK responses
Exit on SIGTERM, no preStop123 / 110 / 129 / 32 / 05,547
226 / 68 / 030 / 19 / 25,556
Graceful shutdown, no preStop10 / 70 / 00 / 21 / 15,576
21 / 140 / 10 / 23 / 05,576
Graceful shutdown, preStop sleep 510 / 0 / 02 / 0 / 15,576
20 / 0 / 00 / 0 / 05,576

Across all client types, errors per run were 195 and 145 with no drain, 92 and 165 with graceful shutdown alone, and 3 and 0 with both, against about 5,600 OK responses per run. That is one server, 200 ms requests and two runs. It shows the direction and which error each change removes. It is not a measured rate, and it does not show the combination reaches zero.

Three readings. Graceful shutdown alone removes most EOFs and leaves connection refused, because new connections still reach a pod whose listener has closed. Only the preStop delay removes those. And the combination is not perfect: run 1 still lost 3 keepalive requests, as we would expect from Shutdown closing idle connections while a client reuses them. Non-idempotent keepalive clients need the next fix too.

Keepalive: make the client give up first. With Go's Transport.IdleConnTimeout at 1.5 s against the server's 2 s, the same aimed sweep gave 1,500 of 1,500 OK, all on new connections, in the one run we tried it. Check the idle timeout of every hop: client, proxy, load balancer and server. Each must time out before the one behind it.

Retries: only for safe requests. Go's Transport replays idempotent requests on a reused connection, and GET in the same sweep gave 0 errors in 1,500 tries, twice. It also treats requests with an Idempotency-Key header as idempotent; we did not test that. A POST may have reached the server, as the ACK in the reset capture shows, so a blind retry can apply it twice.

Middlebox: fix the device. Find its idle timeout or rule. The reset is its decision, and no change on the server will stop it.

How do you verify the fix?

Run steady traffic through three consecutive rollouts and count errors by exact string, as in the table above. Pass condition: zero reset, refused and EOF on new connections, and keepalive errors only at a rate your retries cover. Watch for at least as long as your longest idle timeout.

How do you stop it coming back?

Keep that rollout test in CI. It catches a removed preStop or a broken SIGTERM handler, neither of which shows up in pod status.

For a signal in production, rate(node_netstat_Tcp_OutRsts[5m]) is in node_exporter's default netstat fields. We did not run it in the lab. It counts resets a node sent, including normal ones, so alert on a change from baseline. Client error counts by exact string are better if you have them.

Common mistakes

  • Reading every failure as a reset. Empty reply and socket hang up were a FIN in every capture here. Node's code=ECONNRESET on socket hang up hides this.
  • Trusting the string alone. use of closed network connection, RemoteDisconnected and broken pipe each appeared here with a RST and no FIN.
  • Blaming the network first. Apart from the firewall rules, the sender here was always the server's own kernel, doing its job.
  • Stopping at graceful shutdown. Without the preStop delay our clients still got 91 and 163 refused connections in the two runs.
  • Trusting pod status. The Deployment reported success while clients failed.
  • Raising timeouts on one hop only. The client's idle timeout must stay below the server's.

Connection reset by peer in SSH

If you landed here from ssh, the meaning is the same: something sent a RST. Where it happens tells you more than the words do. We tested OpenSSH 10.0p2 in plain Docker with an iptables -j REJECT --reject-with tcp-reset rule on the server.

Reset before the first read, rule matching the client's first ACK:

ssh: connect to host 172.18.0.2 port 2222: Connection reset by peer

Reset when the client sends its banner, the common form:

kex_exchange_identification: read: Connection reset by peer
Connection reset by 172.18.0.2 port 2222

Reset during a logged-in session:

Read from remote host 172.18.0.2: Connection reset by peer
client_loop: send disconnect: Broken pipe

The first two mean the session never reached authentication, so changing keys will not help. Look at firewalls, intrusion prevention tools and any proxy on the path, then the sshd log on the server. A MaxStartups drop did not give a reset in our test: the client printed Connection closed by 10.244.2.14 port 2222, and sshd logged drop connection #1 from [10.244.2.13]:48936 on [10.244.2.14]:2222 Maxstartups. We tested only this version and MaxStartups=1:100:1. The banner reset rule behaved differently in that cluster setup: sshd had already sent a FIN for the drop, so a RST arrived on the wire and the client still printed Connection closed by. The cases above are from plain Docker.

What we saw in the lab

Scenario 24 is new. ./lab.sh selftest 24-connection-reset-by-peer passed (broken 24-connection-reset-by-peer after 0s, selftest: 1 passed, 0 failed, from selftest.log). The fault is an api release with a SIGTERM handler that calls os._exit(0) and an uploader streaming to it. Its log line in the quoted run:

import failed after 7667712 bytes: BrokenPipeError: [Errno 32] Broken pipe

This goes against our own scenario title and alert text: in all three runs whose log we kept the uploader logged BrokenPipeError (after 7,667,712, 3,997,696 and 4,784,128 bytes), never ConnectionResetError, and check.sh accepts either error. This client has one thread and no read in progress, so by the logic above a FIN came first, but that is an inference: we captured no packets on the shop app. The resets on this page come from repro.sh, not from the shop app. Other results:

  • We expected a crash to mean a reset. With the request fully read, it gave a FIN for all four clients.
  • On Go, about one keepalive race in ten was a reset (33 of 287 over two runs). Most were EOF.
  • The same client's error text changed between runs of the same test, so match on a family of strings.
  • curl's refused message with -sS does not contain "refused".
  • repro.sh hung in two versions because sleep infinity as PID 1 does not reap children, so pgrep kept finding zombies of our finished load client. Run 42130110881 also lost the server capture to a misplaced grep flag, so case 09 is from the later run only.

The Aurora, HolmesGPT and K8sGPT investigations have not been run on this scenario, because there is no LLM key in the lab's Actions runner. When they are, the trace and grade will go in the lab folder and on this page, wrong turns included.

How Aurora handles this

Aurora receives an alert and investigates with read-only kubectl under its default observability_only command policy, choosing the commands itself. It records every tool call and its output, cites them in the report, and lists suggested fixes separately; mutating commands are blocked by default, so it proposes the change rather than applying it. This failure will test it: pods, Services and the Deployment all look healthy here, and the evidence is in client logs and rollout timing. We do not expect it to take a packet capture under that policy; that is a prediction, not a result.

Related: 502 Bad Gateway in nginx and Kubernetes, 504 Gateway Timeout, Service has no endpoints, OOMKilled, liveness probe failed, NetworkPolicy blocking traffic, and the root cause analysis guide for SREs.

Sources and verification

Questions

Other runbooks