Node.js ECONNRESET: Where It Comes From and What to Do

Symptom

Random "read ECONNRESET" crashes or 500s under load.

Root cause

The remote end closed the TCP connection mid-flight (idle timeout, restart, LB drain).

Fix, in order

1. Handle it on the socket, not the processreq.on('error', e => { if (e.code === 'ECONNRESET') return retry(); throw e })
2. Set keep-alive on outbound agentsnew https.Agent({ keepAlive: true, keepAliveMsecs: 30000 })
3. Add retries with jitter for idempotent callsretryOn(error => error.code === "ECONNRESET")

Prevent it coming back

Treat any upstream as a service that restarts: timeouts + retries + circuit breaker.

Run it on clean infra

Spinning up a fresh box to reproduce or escape this error?

DevOps tools shelf

Related

Cloud & DevOps tool comparisons · Hardware build guides

NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.

Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog