HTTP client timeout with AbortController (fetch)

3146
0

Unbounded network calls eventually will hang, and then your Node process gets stuck with slow requests chewing up the connection pool. I wrap fetch with an AbortController timeout so every outbound call has an upper bound. The key is distinguishing between a timeout and an HTTP error so you can decide what to retry. I also attach request ids and log the upstream hostname and duration. In practice, consistent timeouts are one of the highest-leverage reliability changes you can make, because they turn an unbounded failure mode into a controlled one. Once timeouts are consistent, you can tune retries and circuit breakers with real data.