Skip to content
Latchkey

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.

node
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.

src/http.ts
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.

  1. Add a readiness/health check before the first request.
  2. Increase the server response timeout if it is genuinely slow.
  3. 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.

Frequently asked questions

What causes ""socket hang up""?
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.
How do I fix "socket hang up"?
Set an explicit request timeout and retry the request when it fails with a hang up.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card