Troubleshooting 4 min read

Connection Reset Through a Proxy: Causes and Fixes (ECONNRESET, curl 56)

A reset is a connection being torn down without a goodbye. When it happens tells you who did it, and that tells you what to change.

A connection reset through a proxy means one side of the connection sent a TCP reset (RST) and tore it down abruptly. Your client reports it as "Connection reset by peer", ECONNRESET, curl error 56 or 35, or Python's ConnectionResetError. The reset could come from the proxy, from the exit, from the website, or from something on your own network. The moment it happens is the best clue to who sent it.

When Did the Reset Happen?

Use curl -v and note the last line before the error:

curl -v -x http://USERNAME:[email protected]:8080 https://example.com -o /dev/null
  • Before or right after "> CONNECT", with no response: you're probably talking to the wrong port or protocol (an HTTP client on the SOCKS port 1080, or vice versa), or a firewall on your network is killing the connection.
  • After "200 Connection established" but during the TLS handshake (curl error 35): the website or a protection layer in front of it closed the connection. Common with bot protection that rejects certain TLS fingerprints, and occasionally an exit dropping.
  • After the response started arriving (curl error 56, "Recv failure: Connection reset by peer"): the exit or the website dropped mid-transfer.
  • On the first request after an idle period in a long-running program: a stale pooled connection. More on that below.

Cause 1: Stale Keep-Alive Connections

This is the most common cause in long-running scripts and the most confusing, because it looks random. Your HTTP client keeps idle connections in a pool to reuse them. Meanwhile the proxy, the exit or the website closes connections that have been idle too long. The next time your client picks that connection from the pool and writes a request, it gets a reset.

Fixes, from simplest:

  1. Retry once on reset for idempotent requests (GET, HEAD). The retry opens a fresh connection and succeeds.
  2. Shorten your client's idle timeout so it discards connections before the other side does. In Node.js, pass a timeout to your agent so idle sockets are destroyed, or create the agent with keepAlive: false for proxied requests.
  3. If you rotate IPs per request anyway, don't pool connections to the proxy at all. You lose little performance and the problem disappears.

Cause 2: The Target Rejects Your TLS Handshake

Some protection systems reset connections whose TLS ClientHello doesn't look like a mainstream browser, instead of returning a 403. Symptoms: resets on one specific site, always at the handshake, while the same URL loads in a real browser through the same proxy. Updating your HTTP library and OpenSSL sometimes helps; using a real browser engine is the reliable option. If the site clearly doesn't want automated clients, respect that; see are proxies legal.

Cause 3: The Exit Dropped

Residential and mobile exits are real devices on consumer connections. They can lose connectivity mid-request. With rotating sessions the retry goes through a different exit and works. With a sticky session (USERNAME-session-abc123-time-10), repeated resets mean the exit is gone; switch to a new session id.

Cause 4: Protocol Mismatch

  • An HTTP proxy URL pointed at port 1080, or a socks5:// URL pointed at 8080. Use http:// with 8080 and socks5:// or socks5h:// with 1080.
  • An https:// proxy URL, which makes your client start TLS with the proxy itself. Use http:// for the proxy. See SSL errors through a proxy.

Cause 5: Your Network

Corporate firewalls, school networks and some antivirus web shields reset connections to unknown proxies. If resets happen on every request regardless of target, try from a different network such as a phone hotspot. If it works there, the local network is the cause.

A Retry Wrapper for Resets in Python

import time
import requests

PROXY = "http://USERNAME:[email protected]:8080"
proxies = {"http": PROXY, "https": PROXY}

RETRYABLE = (
    requests.exceptions.ConnectionError,  # includes resets and ProxyError
    requests.exceptions.ChunkedEncodingError,  # reset mid-body
)

def get(url, attempts=3):
    for i in range(attempts):
        try:
            return requests.get(url, proxies=proxies, timeout=(10, 30))
        except RETRYABLE as e:
            if i == attempts - 1:
                raise
            print(f"reset/connection error, retrying: {e.__class__.__name__}")
            time.sleep(1 + i * 2)

print(get("https://example.com").status_code)

Using requests.get rather than a shared Session means each attempt opens a fresh connection and gets a fresh IP, which is what you want after a reset. For Node.js specifics see Node.js ECONNRESET with proxies.

Stable Connections with NodeProxies

Match the scheme to the port (http:// on 8080, socks5h:// on 1080), retry idempotent requests once on reset, and avoid long-lived idle pools when rotating. If you're new, create an account and test with a 100 MB plan; per-GB rates are on the pricing page.

FAQ

What does connection reset by peer mean with a proxy?

Something in the chain closed the TCP connection abruptly. When it happened (before CONNECT, during TLS, mid-response or after idling) tells you whether it was the proxy setup, the website, the exit or a stale connection.

Why do I get random connection resets in a long-running scraper?

Most likely your client is reusing idle pooled connections that the other side already closed. Retry once on reset, or disable pooling when rotating IPs.

Is curl error 56 a proxy problem?

Not necessarily. It means the connection was reset while receiving data, which can come from the exit or the website. Retry with a new IP and check whether it's limited to one site.

NodeProxies

Ready to get started?

90M+ residential, mobile & datacenter proxies. Datacenter from $0.30/GB, residential from $0.42/GB. No contracts.

Create free account