Originally published on proxymint.
Connection reset by peer through a proxy, tested: what curl, Python and Node print at each stage, proxy or target, and which resets are safe to retry.
TL;DR
- Run curl -v once and see whether the reset lands before or after CONNECT tunnel established. Before it, the proxy refused you and the target never saw a byte. After it, either side could have done it, so request a known-good URL through the same proxy to find out.
- A target that resets often shows up as a clean close, not a reset. proxy.py closed its side normally, so curl printed (18) transfer closed with 990 bytes remaining, or (52) Empty reply from server, with no ECONNRESET anywhere in the output.
- Don't trust requests when it says Unable to connect to proxy. It printed that for a reset from the target after the tunnel was open and the request had been delivered, and urllib3 then resent the POST four times under Retry(total=3).
- Resets that only appear under load are usually a connection or rate limit. The output matches a plain proxy refusal, and a short retry loop made it worse, while capping concurrency at the limit got 5 of 5 through.
Key takeaways
- Retry by method, not by error text. A reset GET is safe to send again. A POST goes again only with an idempotency key, because in the test the target had already processed it when the reset arrived.
- Log err.cause in Node. fetch only says fetch failed, and the cause holds the part you need, read ECONNRESET or SocketError: other side closed. Node http also tags a clean close socket hang up with code ECONNRESET.
- Keep your pool's idle timeout shorter than the proxy's. Clients survived an idle close that happened well before the next request. The one that broke them was a reset crossing the next request on a reused socket, and only curl and aiohttp (GET only) recovered on their own.
- Fix an idle-timeout reset at the timeout, not in the retry loop. A 3 second target behind a 1 second proxy idle limit failed four times out of four and took about 6 seconds to give up.
Read the full guide on proxymint, with the commands, tables and sources.
