ECONNRESET / read ECONNRESET (Node, nginx, databases)
The other side (or a proxy in the middle) aborted an established connection. You had a socket; then it was reset. That is different from never connecting.
What ECONNRESET means
Errno ECONNRESET is “Connection reset by peer”: the remote end (or a middlebox) sent a TCP RST, or the local stack treats a half-closed socket as reset. In Node you often see Error: read ECONNRESET, write ECONNRESET, or the older socket hang up. Axios/fetch wrap the same cause.
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:…)
# curl: Recv failure: Connection reset by peer
# Go: read: connection reset by peer
Usual causes
- Idle timeout on a proxy — nginx
proxy_read_timeout, AWS ALB/NLB idle timeout, Cloudflare, or a corporate proxy closes long-lived or slow responses. The client’s next read gets RESET. - Upstream died mid-request — the app process OOM-killed, segfaulted, or the pod was restarted. Short-lived 502s often accompany this; see 502 Bad Gateway.
- TLS vs plain HTTP mismatch — speaking HTTPS to a cleartext port (or the reverse) can look like an immediate reset. Related: SSL wrong version number.
- Request too large / WAF reject — some proxies RST oversized or blocked bodies instead of a clean 413. See 413 Request Entity Too Large.
- Keep-alive reuse of a dead socket — HTTP agent reuses a connection the server already closed. Retry once on ECONNRESET; libraries often do.
- Database / Redis max connections — the server closes excess clients. Check server logs for “too many connections” or forced disconnects.
What to try
- Reproduce with
curl -vto the same URL from the same network namespace as the app. - Compare client timeout vs proxy idle timeout; lengthen the proxy side if responses are legitimately slow, or stream/chunk so activity continues.
- Disable keep-alive once to test:
Connection: closeor a fresh agent per request (debug only). - Watch upstream logs and restarts at the same timestamps as the resets.
- For Node HTTP clients, catch
error.code === 'ECONNRESET'and retry idempotent GETs with backoff.
# nginx: raise read timeout for a slow upstream (example)
proxy_read_timeout 120s;
proxy_send_timeout 120s;
ECONNRESET vs neighbours
| Error | Rough meaning |
|---|---|
ECONNRESET | Had a connection; peer aborted it |
ECONNREFUSED | Nothing accepted the port |
ETIMEDOUT | No useful reply in time |
ENOTFOUND | DNS miss — see getaddrinfo ENOTFOUND |
socket hang up | Often the same family as reset / premature close in older Node |
Related
ERR_EMPTY_RESPONSE · ETIMEDOUT · ECONNREFUSED · getaddrinfo ENOTFOUND · 502 Bad Gateway · TypeError: Failed to fetch · too many redirects · WebSocket connection failed · WebRTC ICE failed · HTTP 206 Partial Content · download won't resume
Questions
What does read ECONNRESET mean?
While reading from a TCP socket, the remote side (or a proxy) reset the connection. Investigate timeouts, crashes, and TLS/port mismatches.
Is ECONNRESET the same as ECONNREFUSED?
No. REFUSED means connect never succeeded. RESET means a connection existed and was aborted.
Why only in production?
Load balancers and WAFs add idle limits and body limits you do not have on localhost.
Should I always retry?
Retry idempotent requests (GET, some PUT) with backoff. Do not blindly retry non-idempotent POSTs without knowing the server state.
Can keep-alive cause it?
Yes — reusing a socket the server already closed. A single retry usually recovers.
Does nginx show anything?
Check error.log for upstream prematurely closed connection, and align proxy_read_timeout with your slowest honest response.
Published .