# Connection reset by peer (ECONNRESET) through a proxy

> Connection reset by peer (ECONNRESET, socket hang up) through a proxy: stale keep-alive connections, dropped exits, firewalls. Causes and fixes.

- URL: https://crawlrelay.com/docs/errors/connection-reset/
- Last updated: 2026-10-13
- Publisher: CrawlRelay (https://crawlrelay.com)

Socket error: the exact message in each tool, the likely causes in order, and the fix that works.

**Quick answer — What does Connection reset by peer (ECONNRESET) mean with a proxy?**

**Connection reset by peer** means the other end closed the TCP connection abruptly, with a reset instead of a normal close. Through CrawlRelay residential proxies, the usual causes are a reused keep-alive connection that went stale, an exit that dropped, or a target firewall that cuts connections. Retry safe requests on a new connection and do not keep idle connections too long.

## Connection reset by peer (ECONNRESET) at a glance

| Attribute | Value |
| --- | --- |
| Error | Connection reset by peer (ECONNRESET) |
| Type | Socket error |
| Sent by | The network stack, after the other side closed the connection abruptly |
| Defined in | TCP reset (RST segment): RFC 9293 |
| Retry it? | Yes, for safe requests, on a new connection |
| First check | See whether resets follow idle reused connections or new ones |

## What does Connection reset by peer (ECONNRESET) mean?

TCP can end a connection gracefully or with a reset. A reset tells your machine that the other side discarded the connection, so any data in flight is lost. Python raises `ConnectionResetError`; Node.js raises `ECONNRESET` or 'socket hang up'.

The 'peer' is whoever your socket talks to directly, which is the proxy gateway. The reset can still originate further along the chain and be passed on.

## What does a connection reset look like in Python, curl, Node.js and browsers?

The same failure prints differently in every tool. These are the messages to search your logs for:

- **Python:** `ConnectionResetError: [Errno 104] Connection reset by peer`, or `[WinError 10054]` on Windows
- **requests:** `ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(...)))`
- **Node.js:** `Error: socket hang up` or `read ECONNRESET`
- **curl:** `curl: (56) Recv failure: Connection reset by peer`

## What causes a connection reset?

Most likely first:

- **Stale keep-alive connections.** A pooled connection sat idle and was closed on the other side; the next request on it fails at once.
- **A dropped exit**, which ends every connection that used it.
- **A target firewall** that resets connections it does not like.
- **Long uploads or downloads** cut by an idle limit somewhere on the path.

## How do I diagnose a connection reset step by step?

1. Check whether resets happen on the first request of a connection or after idle reuse.
2. Count resets per host: one host means the target; all hosts means the path or the pool.
3. Note the timing: resets after exactly N seconds idle point to an idle limit.

*Test the failing URL with curl (HTTP port, verbose)*

```bash
# Use the URL that fails; with https://api.ipify.org instead, you test the gateway alone.
# "HTTP/1.1 200 Connection established" first, then the site's own status: the site answered.
curl -v -x http://USERNAME:PASSWORD@gw.crawlrelay.com:7777 https://TARGET_URL

# Same test through the SOCKS5 port, with DNS resolved at the exit
curl -v --socks5-hostname gw.crawlrelay.com:7778 --proxy-user USERNAME:PASSWORD https://TARGET_URL
```

## How do I fix a connection reset?

- **Retry idempotent requests** (GET, HEAD) once on a new connection.
- **Shorten idle reuse**: close pooled connections that have been idle for more than a few seconds, or open a new connection per request when you need a new IP anyway.
- **End a sticky session** that resets repeatedly and start a new one.
- **Slow down** on hosts that reset under load.

*Python: retry with Retry-After, exponential backoff and jitter*

```python
import random
import time

import requests

PROXY = "http://USERNAME:PASSWORD@gw.crawlrelay.com:7777"
PROXIES = {"http": PROXY, "https": PROXY}
RETRY_STATUSES = {429, 502, 503, 504}


def fetch(url, attempts=5, timeout=(10, 30)):
    for attempt in range(attempts):
        try:
            r = requests.get(url, proxies=PROXIES, timeout=timeout)
        except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
            r = None  # dropped exit, reset or timeout: a new connection gets a new exit
        if r is not None and r.status_code not in RETRY_STATUSES:
            return r
        retry_after = r.headers.get("Retry-After", "") if r is not None else ""
        if retry_after.isdigit():
            wait = int(retry_after)
        else:
            wait = min(60, 2 ** attempt) + random.uniform(0, 1)
        time.sleep(wait)
    raise RuntimeError("giving up on %s after %d attempts" % (url, attempts))
```

## Should I retry after a connection reset?

Retry a reset once for safe requests such as GET. Do not blindly retry POST requests that change data: the first one may have been processed. A burst of resets on one host means that host is cutting you off; lower the pace there.

## How does Connection reset by peer (ECONNRESET) apply to CrawlRelay?

On CrawlRelay, rotation happens per new connection. A client that keeps one connection alive keeps the same exit for every request on it, so a dropped exit resets that connection. Reopen the connection to get a fresh exit; the [sessions guide](https://crawlrelay.com/docs/sessions/) shows the patterns.

Gateway: `gw.crawlrelay.com`, port 7777 (HTTP, HTTPS through CONNECT) and port 7778 (SOCKS5). Username format: `USERNAME-country-{cc}-state-{state}-city-{city}-zip-{zip}-asn-{asn}-session-{id}-ttl-{minutes}`. Related: [502 Bad Gateway](https://crawlrelay.com/docs/errors/502-bad-gateway/) · [Read timed out](https://crawlrelay.com/docs/errors/read-timeout/) · [Sessions guide](https://crawlrelay.com/docs/sessions/).

## Connection reset by peer (ECONNRESET): questions developers ask

### Why do I get 'socket hang up' in Node.js with a proxy?

The connection closed before a response arrived. With a proxy, common causes are a reused keep-alive socket that went stale, an exit that dropped, or a target that cut the connection. Retry GET requests on a new socket and limit how long idle sockets stay in the pool.

### Is a connection reset a sign that I am blocked?

Sometimes. Firewalls can reset connections from clients they reject, but resets also happen for harmless reasons on any residential network. Look at the pattern: resets limited to one host and growing with your request rate suggest the host is pushing back.

### Should I disable keep-alive for scraping?

Not completely. Keep-alive saves time when you send several requests to the same host through one sticky exit. When you want a new IP on every request, a new connection per request is the cleaner choice. Mixing both carelessly is what produces stale-connection resets.

## Other proxy errors in this reference

- [401 Unauthorized vs 407](https://crawlrelay.com/docs/errors/401-unauthorized/)
- [403 Forbidden](https://crawlrelay.com/docs/errors/403-forbidden/)
- [407 Proxy Authentication Required](https://crawlrelay.com/docs/errors/407-proxy-authentication-required/)
- [429 Too Many Requests](https://crawlrelay.com/docs/errors/429-too-many-requests/)
- [502 Bad Gateway](https://crawlrelay.com/docs/errors/502-bad-gateway/)
- [503 Service Unavailable](https://crawlrelay.com/docs/errors/503-service-unavailable/)
- [504 Gateway Timeout](https://crawlrelay.com/docs/errors/504-gateway-timeout/)
- [Cannot connect to proxy (ProxyError)](https://crawlrelay.com/docs/errors/cannot-connect-to-proxy/)
- [Connection reset by peer (ECONNRESET)](https://crawlrelay.com/docs/errors/connection-reset/)
- [ERR_PROXY_CONNECTION_FAILED](https://crawlrelay.com/docs/errors/err-proxy-connection-failed/)
- [ERR_TUNNEL_CONNECTION_FAILED](https://crawlrelay.com/docs/errors/err-tunnel-connection-failed/)
- [Read timed out (ReadTimeout)](https://crawlrelay.com/docs/errors/read-timeout/)
- [SOCKS5 proxy errors](https://crawlrelay.com/docs/errors/socks5-proxy-errors/)
- [SSL: CERTIFICATE_VERIFY_FAILED](https://crawlrelay.com/docs/errors/ssl-certificate-verify-failed/)
- [SSL: WRONG_VERSION_NUMBER](https://crawlrelay.com/docs/errors/ssl-wrong-version-number/)

**Residential proxies with docs that cover the failure cases** CrawlRelay residential proxies from $0.50/GB, traffic that never expires. [See pricing](https://crawlrelay.com/pricing/) · [Quick start](https://crawlrelay.com/docs/)

---

CrawlRelay: CrawlRelay is a developer-first rotating residential and 4G/5G mobile proxy service for scrapers and AI data pipelines: non-expiring pay-as-you-go traffic from $0.50/GB, paid in crypto, with no ID upload. No KYC — no ID, no selfie, no documents. Pay in crypto.
