Skip to content
MtrXTools

Error: socket hang up

The server closed the connection before replying

Seen in Node.js http/https, axios, node-fetch, request, npm

Node.js sent a request but the connection closed before any response arrived (code ECONNRESET).

Common causes

  • The server or a proxy closed a reused keep-alive connection just as a new request was sent on it.
  • The server crashed, timed out or never called res.end() on its side.
  • Sending plain HTTP to a TLS port, or HTTPS to a plain HTTP port.
  • A proxy, WAF or load balancer dropped the request.

How to fix it

  1. Retry idempotent requests; set the client keep-alive timeout lower than the server keep-alive timeout.
  2. Check server and proxy logs for errors or timeouts at that moment.
  3. Check the URL scheme and port match.
  4. If you run the server, make sure every code path ends the response.
Check the port is open

Got a different message? Paste it into the error explainer.

Related errors

All 34 Command line & code errors