Geonode logo
Network errors

How to Fix ECONNRESET (Connection Reset by Peer)

Tell a stale keep-alive connection from a proxy or server drop, then fix it in Python, Node.js or cURL.

Updated

TL;DR

ECONNRESET, or connection reset by peer, means the server or proxy at the other end aborted an open TCP connection and your operating system reported it to your client. The fastest fix is to send a GET or other idempotent request again, once, over a fresh connection.

What ECONNRESET looks like in each client

The error number depends on the system: 54 on macOS, 104 on Linux, 10054 on Windows.

WhereWhat you see
Node.js http and https (errno, code and syscall printed below)Error: read ECONNRESET
Node.js http, reset during the response body (code ECONNRESET)Error: aborted
Node.js fetch() (err.cause is Error: read ECONNRESET)TypeError: fetch failed
axios in Node.js, as console.log prints itAxiosError: read ECONNRESET
Python requests on Linuxrequests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Python on WindowsConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
curlcurl: (56) Recv failure: Connection reset by peer

Why this happens

The other side tore the connection down instead of ending it the normal way.

Usually the server or proxy timed out or restarted and no longer knows the connection, so when your client sends data on it, the far end answers with a TCP reset (RST).

Diagnose your ECONNRESET first

Each check points to one cause: a stale pooled connection, the proxy route, or the server itself.

  • Read the word before ECONNRESET; read means the reset arrived while your client was receiving, write means while it was still sending.

  • In Node.js, log req.reusedSocket in the error handler; if it is true, the server likely closed a pooled keep-alive connection as you reused it.

  • Send the same request without the proxy; if only proxied requests reset, look at the proxy route rather than the site.

  • Run curl -v through the proxy to an https:// URL; a reset before the CONNECT reply means the proxy hop dropped you.

  • If you run the server, check its log at the failure time; a crash or restart there explains resets on every open connection.

Solutions ranked by effectiveness

Start with the retry; the other two remove the usual reasons a connection gets reset.

  1. Most common fix

    Retry once on a fresh connection

    Applies when resets come and go. Repeat GET, PUT or DELETE one time, but not a POST that may already have run; curl repeats a reset only with --retry-all-errors.

    import urllib.error
    import urllib.request
    
    url = "https://example.com/"
    for attempt in (1, 2):
        try:
            with urllib.request.urlopen(url, timeout=30) as r:
                print(r.status, len(r.read()), "bytes")
            break
        except (ConnectionResetError, urllib.error.URLError) as e:
            if attempt == 2 or not isinstance(getattr(e, "reason", e), ConnectionResetError):
                raise
  2. Check next

    Drop idle connections before the server does

    Applies when requests after a pause fail. Give your keep-alive agent a timeout below the server's idle limit; Node.js 20 and later lower it further if the server's Keep-Alive hint is shorter.

    const https = require("node:https");
    
    const agent = new https.Agent({ keepAlive: true, timeout: 1500 });
    function get() {
      https.get("https://example.com/", { agent }, (res) => {
        res.resume();
        res.on("end", () => console.log(res.statusCode, "reused connection:", res.req.reusedSocket));
      }).on("error", (err) => console.log("failed:", err.code));
    }
    get();
    setTimeout(get, 3000);
  3. If nothing else works

    Repair the proxy route

    Applies when proxied requests reset on more than one site while direct ones work. Geonode's docs name unstable internet and wrong proxy settings as the most common causes of dropped proxy connections.

    1. Copy host, port and login again from your proxy dashboard and replace the saved entry.

    2. Test the same proxy on another device or network to rule out your connection.

    3. Run fewer threads per proxy; Geonode's docs warn that too many can overload proxies.

Stop the ECONNRESET from coming back

Habits for uploads, Node.js upgrades and servers you run, so connections close cleanly.

  1. For large uploads, send Expect: 100-continue, so the server can refuse before the body goes out.

  2. Retest scripts after moving up from Node.js 18; from version 19 the default agent keeps connections open for reuse.

  3. Before a deploy stops your Node.js server, call server.close(), which closes idle connections and lets busy ones finish.

  4. On servers you run, close in stages (write side first), so a reset cannot erase your last reply.

Proxy refusals you can readGeonode's gateway answers refusals with status codes, and its docs explain each one.
Try residential proxies

Related errors

Learn more

FAQ

It is the POSIX error name for connection reset: the machine on the far side, a website's server or a proxy, killed the TCP connection with a reset packet, so whatever your client was sending or waiting for was lost.

Often it is a timing race: RFC 9112 notes a client may send a new request just as the server closes the idle connection. Gunicorn, for one, drops idle keep-alive connections after 2 seconds by default.

The error alone cannot say: your connection ends at the proxy, so resets reach you through it. After a successful CONNECT, RFC 9110 has the proxy close your side when the site closes, so either may have started it.

Not by itself: server timeouts, restarts and reused idle connections cause it too. If every new connection to one site resets, the site may be refusing you; HTTP/1.1 lets servers reject excessive connections from one client, so open fewer.

A reset is an explicit abort that arrives at once; a timeout means nothing came back before your client's limit ran out. Node.js also tags socket hang up, a connection closed before any response, with the code ECONNRESET.

One automatic retry, because RFC 9110 says a client should not automatically retry a failed automatic retry. If that second attempt fails too, log the URL and requeue it for later instead of looping.

Help tracing dropped connections

Geonode's support team helps diagnose connection issues; include the failing request's details.