Node.js "Error: socket hang up" in CI
Node reports socket hang up when a connection closes before the HTTP response is fully received. It is a special case of ECONNRESET, common with slow servers, timeouts, or transient network drops.
What this error means
An HTTP request fails with Error: socket hang up. The failure is intermittent - the same request succeeds on retry - when the cause is a transient drop rather than a logic error.
Error: socket hang up
at connResetException (node:internal/errors:720:14)
at TLSSocket.socketOnEnd (node:_http_client:519:23)
code: 'ECONNRESET'Common causes
The server closed before responding
A slow or overloaded server, or one that hit its own timeout, closed the socket before sending a full response. The client sees a hang up.
A transient network drop
A momentary disruption between the runner and host tears down the connection mid-response. It is not deterministic.
How to fix it
Add timeouts and retry transient hang-ups
Set an explicit request timeout and retry the request when it fails with a hang up.
const res = await fetch(url, {
signal: AbortSignal.timeout(10000),
});Wait for the dependency to be ready
Ensure the target server is fully up and not still warming before issuing requests in CI.
- Add a readiness/health check before the first request.
- Increase the server response timeout if it is genuinely slow.
- Retry on hang up with a small backoff.
How to prevent it
- Set explicit request timeouts so a slow server fails fast and predictably.
- Retry transient hang-ups with bounded backoff.
- Gate tests on a readiness check for dependent services.