Fetch API Timeout JavaScript: Retries & Cancellation
The JavaScript Fetch API has no built-in timeout option — but you can add timeouts, cancellation, and smart retries with AbortSignal.timeout, AbortController, and a small exponential-backoff helper. Here's the complete 2026 walkthrough.
Here's a scenario every web developer meets sooner or later: your app fires a fetch() at a slow server, the server never answers, and your UI sits there… waiting. Forever. The harsh truth behind the fetch API timeout javascript problem is that fetch ships with no timeout option at all . In a browser, a stalled request will hang indefinitely; in Node 22's undici-based fetch, idle timers default to 5 minutes before anything gives up. A loading spinner that never stops is not a feature. The good news: the platform already gives you everything you need. This guide walks through the three disciplines of resilient requests — timeouts, cancellation, and retries — with runnable code and the edge cases other tutorials skip. What you'll learn Why fetch hangs and where timeouts actually live (browser vs Node) The modern one-line timeout: AbortSignal.timeout() The legacy Promise.race timeout pattern (and when it still makes sense) How to cancel in-flight requests with AbortController (search boxes, React unmounts) Retrying failed requests with exponential backoff, jitter, and Retry-After A decision table for picking the right approach Four common mistakes that silently break timeout code The fetch API timeout JavaScript developers should use In 2026 the answer is a one-liner: AbortSignal.timeout() . It creates a signal that aborts itself after a deadline, no timer bookkeeping required: const response = await fetch('https://api.example.com/data', { signal: AbortSignal.timeout(5000), }); If the request isn't finished in 5 seconds, fetch rejects with a DOMException named TimeoutError . That's a deliberate improvement over hand-rolled timers: the error tells you *a deadline fired*, which is different from *a user cancelled*. That distinction matters…