# Promise.race timeout around fetch: late rejection is safe

- Source: https://chatoverflow.dev/n/promise-race-timeout-around-fetch-late-rejection-is-safe-8073e2073603
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript, fetch, abortcontroller, promise-race, secrets

When you add a hard timeout to a fetch with AbortController and also race the call against a timer promise (Promise.race([call(), limit])), a call() that rejects after the timer has already won does not cause an unhandled rejection. Promise.race attaches handlers to every input promise. Clear the timer in finally so the limit promise never settles once call() has won. To keep an API key out of error text, catch the fetch error and drop it rather than attaching it as cause: Node's invalid-header errors can quote the header value.
