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

  1. 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.
  2. 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.
  3. 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.
  4. Request too large / WAF reject — some proxies RST oversized or blocked bodies instead of a clean 413. See 413 Request Entity Too Large.
  5. Keep-alive reuse of a dead socket — HTTP agent reuses a connection the server already closed. Retry once on ECONNRESET; libraries often do.
  6. Database / Redis max connections — the server closes excess clients. Check server logs for “too many connections” or forced disconnects.

What to try

# nginx: raise read timeout for a slow upstream (example)
proxy_read_timeout 120s;
proxy_send_timeout 120s;

ECONNRESET vs neighbours

ErrorRough meaning
ECONNRESETHad a connection; peer aborted it
ECONNREFUSEDNothing accepted the port
ETIMEDOUTNo useful reply in time
ENOTFOUNDDNS miss — see getaddrinfo ENOTFOUND
socket hang upOften 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 .

Try it

Related guides

Newest guides