Error: socket hang up
Your request was sent, but the server (or a proxy) closed the connection without sending a response.
Quick checks
- Does it fail on the first request or after idle time?
- Are you using `http` to talk to an `https` server (or the reverse)?
- Is there a proxy in between?
Fixes on Mac
Match protocol and port
- Use the
httpsmodule for HTTPS endpoints; plain HTTP to port 443 often ends in a hang-up.
- Use the
Handle stale keep-alive sockets
- Set the client's keep-alive timeout below the server's (for example, a 4-second free-socket timeout if the server closes after 5).
- Retry idempotent requests once on hang-up.
Raise timeouts for slow endpoints
- Server and proxy timeouts that are shorter than the work take produce hang-ups; check both ends.
Fixes on Windows
Same causes
- The fixes are platform-independent; also check corporate proxies.
Other devices
Servers
- Look for crashes or timeouts in the server logs at the time of the hang-up.
Still not working?
ETIMEDOUT is the neighbouring error: the connection or response didn't arrive within the timeout. Check reachability (nc -vz host port) and the server's response time.
See what’s happening
LightAtom's connections view shows connections from your Node process opening and closing, which makes keep-alive reuse visible.
Frequently asked questions
What causes “socket hang up”?
The server or a proxy closed the connection before responding: timeouts, crashes, a stale keep-alive socket, or speaking HTTP to an HTTPS port.
How do I fix socket hang up in Axios or node-fetch?
Check the URL's protocol and port, set sensible timeouts, retry idempotent requests once, and keep client keep-alive timeouts shorter than the server's.
What is ETIMEDOUT?
A timeout: the connection or response took longer than allowed. It points to network reachability or a slow server.