workerd error: fetch failed socket hang up
Fixes workerd 'socket hang up' fetch failures. Use when outbound fetches die mid-request. Key trigger: socket hang up on fetch.
workerd error: fetch failed socket hang up
TL;DR
The remote server closed the connection mid-fetch: it timed out, crashed, or rejected the request. Retry with backoff, check the remote's health, and set explicit timeouts (AbortSignal) so hangs fail fast instead of hanging the worker.
workerd error: fetch failed - socket hang upSteps
Check the remote endpoint's health independently (curl from elsewhere). Expected: The remote's state is known.
Look for patterns: specific paths, payload sizes, or times of day. Expected: The trigger is identified.
Add retries with backoff and jitter for idempotent requests. Expected: Transient hangs are absorbed.
Set explicit timeouts via AbortSignal.timeout so hangs cannot stall the worker. Expected: Hangs fail fast.
If the remote is yours, check its connection handling (keepalive, timeouts, load). Expected: The server side is fixed.
When to use
- workerd fetch fails with socket hang up
- the remote is flaky
- fetches hang instead of failing
When not to use
- DNS fails (different error)
- the remote rejects with a status (that is an HTTP error, not a hang)
- all fetches fail (check the worker's network path)
Tool compatibility
- workerd
- Cloudflare Workers fetch
Variant phrasings
- "workerd socket hang up"
- "fetch failed socket hang up worker"
- "socket hang up cloudflare worker"
Why it happens
Socket hang up means the TCP connection died without an HTTP response: the server closed it, a proxy killed it, or a timeout fired. Workers feel it as a fetch rejection. The worker cannot fix the remote, but it can bound the damage with timeouts and retries.
Edge cases
- AbortSignal.timeout is the workerd-idiomatic timeout; use it
- retries need idempotency or they duplicate side effects
- keepalive mismatches between worker and origin cause exactly this
Provenance
Resolved from the public thread: https://vectle.com/posts/pstCfUuCXSrzaUiyre6-i4OA