Skip to content

Error explained

Error: read ECONNRESET

ECONNRESET means the other side abruptly closed the connection. Most often it is a reused keep-alive connection that the server had already closed.

3 min read8 sectionsUpdated

On this page

Key points

  • "Connection reset by peer" is the same thing in other languages.
  • Keep-alive timeout mismatches cause intermittent resets on idle connections.
  • Proxies and load balancers close idle connections on their own schedule.
  • Safe retries of idempotent requests hide occasional resets.

Common causes

CauseSignsFix
Server closed an idle keep-alive connectionIntermittent, after quiet periodsClient idle timeout shorter than the server’s
Load balancer idle timeoutLong requests or idle sockets reset at a fixed timeAlign timeouts; send keep-alives
Server crashed or restarted mid-requestResets during deploysGraceful shutdown; drain connections
Request too large / rejectedReset right after sending a big bodyCheck body limits on proxy and server
TLS or protocol mismatchReset at connectCheck TLS versions and ports

The keep-alive mismatch

Node's HTTP server closes idle keep-alive sockets after keepAliveTimeout (5 seconds by default). If a client or a load balancer in front keeps idle connections open longer, it may send a request on a socket the server is closing, and gets a reset. The rule: the server's keep-alive timeout must be longer than the idle timeout of whatever connects to it.

javascript
const server = app.listen(8080);
server.keepAliveTimeout = 65_000;   // longer than a 60 s load balancer idle timeout
server.headersTimeout = 66_000;     // must be above keepAliveTimeout

Graceful shutdown

During deploys, stop accepting new connections, let in-flight requests finish, then exit. In Kubernetes, handle SIGTERM and give the pod a short preStop delay so the load balancer stops sending traffic before the process closes its sockets.

Catching it in production

Resets are usually intermittent, which makes them easy to ignore. Traces show which client call failed and to which host; group failures by target and time to see whether they line up with deploys or idle periods.

VitalRix error tracking groups exceptions recorded on OpenTelemetry spans into issues with counts, first and last seen, affected endpoints and versions, and marks an issue as regressed if it comes back after being resolved. Alert rules on error rate per service or endpoint route the problem to the right team before customers report it.

Frequently asked questions

Is ECONNRESET a client or server problem?

Either. It only says the other side reset the connection. Check server logs at that moment; if they show nothing, look at proxies and idle timeouts in between.

Should I retry on ECONNRESET?

For idempotent requests, yes, once or twice with backoff. For payments and other non-idempotent requests, use idempotency keys.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.