ECONNRESET: What It Means and How to Fix It
Error reference
ECONNRESET
Language
Severity
HighWhen it happens
ECONNRESET is a Node.js network error that occurs when a TCP connection is forcibly closed by the remote peer while data is still being transferred.
Potential fixes
Implement retry logic with exponential backoff for transient ECONNRESET errors. Set appropriate keep-alive and timeout settings on your HTTP agent. Monitor for patterns (all requests to one server resetting) to distinguish infrastructure issues from code bugs.
Related errors
Deep dive
ECONNRESET is a Node.js network error that occurs when a TCP connection is forcibly closed by the remote peer while data is still being transferred. Unlike ECONNREFUSED (connection rejected before it starts), ECONNRESET happens mid-connection.
Why it happens
- •The remote server crashes or restarts while a request is in progress.
- •A load balancer or proxy has a shorter idle timeout than your client.
- •The server sends a TCP RST packet to close the connection abruptly.
- •Network equipment (firewalls, NAT) drops an idle connection.
Potential fixes
Implement retry logic with exponential backoff for transient ECONNRESET errors. Set appropriate keep-alive and timeout settings on your HTTP agent. Monitor for patterns (all requests to one server resetting) to distinguish infrastructure issues from code bugs.
Examples
Code that triggers the error
const http = require("http");
const req = http.get("http://example.com/large-file", (res) => {
res.on("data", () => {});
});
// Remote server closes the connection mid-transferError output
Error: read ECONNRESET
at TLSSocket.onConnectEnd (_tls_wrap.js:...)
errno: -54,
code: 'ECONNRESET',
syscall: 'read'Fixed code
const http = require("http");
const req = http.get("http://example.com/large-file", (res) => {
res.on("data", () => {});
res.on("error", (err) => console.error("Response error:", err));
});
req.on("error", (err) => {
if (err.code === "ECONNRESET") {
console.error("Connection reset by peer, retrying...");
}
});Practice in English
How would you explain an ECONNRESET to a fellow dev? Choose the right phrase:
"I hit an error...
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free