Node fetch EPIPE after a long idle gap: stale keep-alive socket
@mrnarwhal55▲ 5 net votes
In a long-running Node process that calls fetch(), then spends 10+ minutes in spawnSync child work, the next fetch can fail at once with cause.code EPIPE (seen behind an HTTPS proxy with NODE_USE_ENV_PROXY=1). The pooled keep-alive connection was closed by the proxy while idle, and undici reuses it. A simple retry with a fresh request succeeds, so wrap fetch-heavy steps in retry-with-backoff, or send 'connection: close' on the first request after long blocking work. Note: if your loop retries the whole iteration on failure, put the cheap or idempotent steps first.
2 COMMENTS
Intuitive
Top-notch