Guide · Scraping practice
socket hang up and ECONNRESET through a proxy in Node.js: axios, got, undici and node-fetch
Error: socket hang up with code ECONNRESET means Node's HTTP client saw the connection close before any response arrived; read ECONNRESET means a TCP reset came in. Through a proxy there are three usual causes: the proxy closed the connection without answering (wrong port or protocol, or the proxy refusing you), a kept-alive connection the proxy closed just as you reused it, or a reset from the proxy or the site. For HTTPS URLs the tunnelling agent often reports the close in its own words: Proxy connection ended before receiving CONNECT response (https-proxy-agent) or tunneling socket could not be established, cause=socket hang up (the tunnel package). Retry resets on idempotent requests at most twice, give every request a hard deadline with AbortSignal.timeout(), and test the proxy with the proxy tester. In our tests axios's built-in proxy option and undici's ProxyAgent never returned at all when the proxy hung up.
Reviewed 14 Nov 2026
The short answer
- "socket hang up" is created by Node's HTTP client when the socket closes or ends before a response. Its code is
ECONNRESETeven when no TCP reset happened. - Keep-alive race, reproduced: the proxy answered the first request and closed the reused connection on the second. http.request, axios and got threw
socket hang upwithreq.reusedSockettrue. Node's docs suggest retrying exactly this case. - axios 1.21.1's
proxyoption tunnels HTTPS through https-proxy-agent 5.0.1. When our proxy closed without answering, the request neither resolved nor rejected, andtimeout: 8000never fired.signal: AbortSignal.timeout(5000)ended it withCanceledError: canceled. - undici 7.30.2's
ProxyAgentkept reconnecting to a proxy that closed without answering: about 16,400 CONNECT requests in 5 seconds on our local test proxy. Aborting the fetch did not stop it;agent.destroy()did. - got retries
ECONNRESETby default (two retries, not for POST): our proxy saw three requests before got threwsocket hang up.
socket hang up vs read ECONNRESET
Both carry err.code === 'ECONNRESET', but they come from different places. In Node's lib/_http_client.js (v22.14.0), socket hang up is a ConnResetException that the HTTP client creates itself when the socket closes or ends while the request still has no response. The connection may have been closed cleanly; the code only says the response never came. read ECONNRESET is the operating system reporting a TCP reset, which Node's error docs describe as a connection "forcibly closed by a peer".
Through a proxy, the peer you talk to is the proxy, so a close or reset looks the same to your code whether the proxy or the site caused it. When it happens tells you more: before any response (proxy side, or the keep-alive race below) or in the middle of a body (the connection was lost while streaming).
What each client printed, by cause
Reproduced on 2026-11-14 with Node 22.14.0 against local test proxies, target https://example.com/ unless noted. "https-proxy-agent clients" means https-proxy-agent 9.1.0 used as the agent for https.get, axios (httpsAgent, proxy: false), got 16.2.0 and node-fetch 3.3.2.
| Cause | What Node printed |
|---|---|
Proxy closes without answering CONNECT | https-proxy-agent clients: Error: Proxy connection ended before receiving CONNECT response (got wraps it in RequestError, node-fetch in FetchError: request to https://example.com/ failed, reason: ...). tunnel 0.0.6: Error: tunneling socket could not be established, cause=socket hang up, code ECONNRESET. axios proxy option and undici ProxyAgent: nothing at all, see the next section |
Proxy closes without answering a plain http:// request | http.get with http-proxy-agent 9.1.0, axios proxy option, got: Error: socket hang up, code ECONNRESET |
| Proxy closes a reused keep-alive connection | http.request, axios, got: Error: socket hang up, code ECONNRESET, req.reusedSocket === true |
Proxy resets the connection after reading CONNECT | https-proxy-agent clients and axios proxy option: Error: read ECONNRESET. undici: TypeError: fetch failed, cause Error: read ECONNRESET. tunnel: Error: tunneling socket could not be established, cause=read ECONNRESET |
Proxy answers 200 to CONNECT, then closes before TLS | Every client above: read ECONNRESET (undici as the cause of fetch failed) |
| Reset in the middle of a response body, tunnel already open | undici: TypeError: terminated, cause read ECONNRESET. node-fetch: FetchError: Invalid response body while trying to fetch ...: aborted. got: ReadError: Content-Length mismatch: expected 100000 bytes, received 157 bytes |
| Nothing listening on the proxy port | Error: connect ECONNREFUSED 127.0.0.1:28099; tunnel: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:28099 |
An http:// proxy URL pointed at a SOCKS5 port behaved like the first row: https-proxy-agent failed with Proxy connection ended before receiving CONNECT response, while axios's proxy option, undici and tunnel waited without an error. For SOCKS5 use socks-proxy-agent with a socks5h:// URL; see SOCKS5 proxy errors.
Two clients that hang instead of failing
The axios proxy option. axios 1.21.1 tunnels HTTPS requests through the https-proxy-agent 5.0.1 it depends on. In that version's response parser the handler for an ended connection only writes a debug line and never rejects, so when our proxy closed without answering, the request stayed pending: still no response and no error after 12 seconds with timeout: 8000. Two fixes, both tested: add signal: AbortSignal.timeout(ms), which ended the request after 5 s with CanceledError: canceled (ERR_CANCELED), or pass https-proxy-agent 9.1.0 yourself as httpsAgent with proxy: false, which failed in 9 ms with Proxy connection ended before receiving CONNECT response.
undici's ProxyAgent. With undici 7.30.2, fetch through a ProxyAgent to a proxy that closed without answering never settled, and the agent kept opening new connections: our local proxy logged about 16,400 CONNECT requests in 5 seconds (on localhost, so the rate is limited only by the round trip). AbortSignal.timeout() ended the fetch with TimeoutError: The operation was aborted due to timeout, but the reconnects went on at the same rate, about 10,000 in the next 3 seconds, until we called agent.destroy(). A loop like that can trip rate limits or abuse protection on the proxy's side, so replace the agent after a timeout (code below).
The keep-alive race: socket hang up on a reused connection
With keep-alive the client sends its next request on a connection that is already open. If the proxy closes that connection at the same moment, for example because its idle timeout ran out, the request goes out on a socket that is closing and the client gets socket hang up without any response. Node's documentation for request.reusedSocket describes this case and suggests retrying when the socket was reused and the error is ECONNRESET.
Our test proxy answered the first request on each connection and closed the connection on the second without answering. The second request failed in all three clients (Error: socket hang up in http.request and axios, RequestError: socket hang up in got) with reusedSocket true. A new connection then works, so one retry is the right answer. got does this by default: its documented defaults retry ECONNRESET up to twice for GET, HEAD, PUT, DELETE and a few other methods, not POST, and our proxy saw three attempts. With axios, write the retry yourself (code below).
On a rotating proxy a new connection can also mean a new exit IP, because rotation happens per connection; with a sticky session the retry keeps the same exit (rotating vs sticky sessions).
Checks before you add retries
- Run the proxy string through the proxy tester. If it fails there, the problem is the endpoint or the credentials, and no retry will fix it.
- Match agent and port: an HTTP agent needs the proxy's HTTP port and an
http://URL. ARC's connection strings have the formhttp://USERNAME:PASSWORD@proxy.arcproxies.io:8000. - Retry only idempotent requests (GET, HEAD), only on
ECONNRESET, and at most twice. Retries cost bandwidth and add load; the 429 guide covers backoff with jitter. - Give each request a hard deadline with
AbortSignal.timeout(). A library's own timeout may not cover the proxy handshake, as the axios case shows. - Log
err.code,err.causeand, with Node's http module,req.reusedSocket. Together they separate the causes in the table above. - Client setup with a proxy: axios, node-fetch and undici.
Code
Worked example
import axios from 'axios';import { HttpsProxyAgent } from 'https-proxy-agent';// One agent for all requests. https-proxy-agent 9 rejects at once when the proxy hangs up.const agent = new HttpsProxyAgent('http://USERNAME_pool-arcfast_country-de:PASSWORD@proxy.arcproxies.io:8000', { keepAlive: true });export async function get(url) { for (let attempt = 1; ; attempt++) { try { return await axios.get(url, { httpAgent: agent, httpsAgent: agent, proxy: false, // do not let axios install its own tunnel agent timeout: 30_000, signal: AbortSignal.timeout(45_000), // hard deadline for the cases where timeout never fires }); } catch (err) { if (err.code === 'ECONNRESET' && attempt < 3) continue; // GET only: retry a reset twice throw err; } }}import { ProxyAgent, fetch } from 'undici';const PROXY = 'http://USERNAME_pool-arcfast_country-de:PASSWORD@proxy.arcproxies.io:8000';let dispatcher = new ProxyAgent(PROXY);export async function get(url) { try { return await fetch(url, { dispatcher, signal: AbortSignal.timeout(30_000) }); } catch (err) { if (err.name === 'TimeoutError') { // The abort ends this fetch, not the agent's reconnects: replace the agent. const old = dispatcher; dispatcher = new ProxyAgent(PROXY); await old.destroy(); } throw err; }}FAQ
Questions
Something not covered? Write to contact@arcproxies.io.
What does Error: socket hang up mean in Node.js?
Node's HTTP client saw the connection close before any response arrived. Through a proxy, the proxy closed it: because the port or protocol is wrong, because it refused you, or because it closed a kept-alive connection just as you reused it. The error code is ECONNRESET even if no TCP reset happened.
Why do I get socket hang up only on some requests through a proxy?
Usually the keep-alive race: the proxy closes an idle connection at the moment your client reuses it. The failed request has req.reusedSocket set to true. Retry such requests once on a new connection; got does this by default.
What is the difference between socket hang up and read ECONNRESET?
socket hang up is created by Node's HTTP client when the connection ends before a response, whether it was closed cleanly or not. read ECONNRESET is the operating system reporting that the other side reset the connection. Both have the code ECONNRESET.
What does tunneling socket could not be established, cause=socket hang up mean?
The message comes from the tunnel package (we ran 0.0.6). It sent CONNECT to the proxy and the proxy closed the connection without answering. With cause=read ECONNRESET the proxy reset it; with statusCode= the proxy answered with that status. Check the proxy's host, port and protocol.
Why does axios hang with a proxy instead of throwing?
In our tests axios 1.21.1's proxy option tunnels HTTPS through https-proxy-agent 5.0.1, which ignores a proxy that closes without answering. The request never settled and the timeout option did not fire. Add signal: AbortSignal.timeout(), or pass https-proxy-agent 9 as httpsAgent with proxy: false.
Does undici retry through a proxy?
Against a proxy that closed without answering, undici 7.30.2's ProxyAgent kept reconnecting in a loop, about 16,400 times in 5 seconds on localhost, and the fetch never settled. Aborting the fetch did not stop the loop; destroying the agent did.
Sources & review
Last reviewed by the ARC Proxies team. Prices are read from the live catalog at build time.
- [1]Node.js: lib/_http_client.js at v22.14.0 ("socket hang up")
- [2]Node.js: HTTP: request.reusedSocket (v22 docs)
- [3]Node.js: Errors: Common system errors (ECONNRESET, ECONNREFUSED)
- [4]https-proxy-agent 9.1.0: dist/parse-proxy-response.js ("Proxy connection ended before receiving CONNECT response")
- [5]https-proxy-agent 5.0.1: dist/parse-proxy-response.js (onend does not reject)
- [6]axios 1.21.1: lib/adapters/http.js (CONNECT tunnelling for the proxy option)
- [7]tunnel 0.0.6: lib/tunnel.js ("tunneling socket could not be established")
- [8]Got: Retry API (default limit, methods, error and status codes)
- [9]undici 7.30.2: lib/dispatcher/proxy-agent.js ("Proxy response (...) !== 200 when HTTP Tunneling")
Next
Where to go from here
Guides