ECONNRESET
Linux / POSIXERRORNotableNetworkHIGH confidence

Connection Reset by Peer

What this means

The remote end of a TCP connection sent a RST packet, abruptly terminating the connection. This can happen when the remote server crashes, when an idle connection is closed by a load balancer, or when the remote process exits while data is in transit.

Why it happens
  1. 1The server process crashed while the client was reading a response.
  2. 2A load balancer or firewall closed an idle connection after a timeout.
  3. 3The remote process closed the connection without reading all pending data.
  4. 4A network appliance forcibly reset the connection.
How to reproduce

A long-running HTTP connection is reset by a load balancer idle timeout.

trigger — this will error
trigger — this will error
// Node.js socket error handling
const net = require("net");
const sock = net.connect(8080, "host");
sock.on("error", (err) => {
  if (err.code === "ECONNRESET") {
    // Connection was reset - reconnect with backoff
  }
});

expected output

Error: read ECONNRESET
    at TLSSocket.onConnectEnd (_tls_wrap.js:1495:19)

Fix

Implement reconnect logic with exponential backoff

WHEN For clients that should recover from transient connection resets

Implement reconnect logic with exponential backoff
async function connectWithRetry(host, port, retries = 5) {
  for (let i = 0; i < retries; i++) {
    try {
      return await connect(host, port);
    } catch (err) {
      if (err.code !== "ECONNRESET" || i === retries - 1) throw err;
      await sleep(Math.pow(2, i) * 100); // exponential backoff
    }
  }
}

Why this works

Exponential backoff avoids overwhelming a recovering server while ensuring the client eventually reconnects.

Sources
Official documentation ↗

Linux Programmer Manual errno(3)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors