Key Takeaways
Promise.race adopts the first settlement without automatically cancelling a losing fetch. For client cancellation, pass an AbortController signal to fetch and abort at the deadline, clearing the timer when the operation ends. Client abort does not prove that server work was cancelled or a write rolled back.
- In the controlled local case, race returned timeout while the original request later returned done.Read the supporting section: Hold a response open before timing out
- Pass the signal to the actual fetch and keep response-body reading and failure paths within timer cleanup.Read the supporting section: Wire cancellation to the request
- Client abort is not server rollback evidence; check operation state before retrying a request with side effects.Read the supporting section: A disconnected client does not settle server state
In this article
Hold a response open before timing out
The Promise.race reference separates choosing a settlement from cancelling other work. On December 1, 2026, the editor used Node.js 22.23.2 and an isolated local HTTP server with a response gate: the server accepted the request but withheld its response until the timeout branch settled.
The outer result was timeout while the response remained unfinished. Releasing the gate then allowed the original fetch to read done. This checks ordering without depending on a real website’s speed; it is not a latency, billing or cancellation test of a model provider.
| Step | Observation | Not established |
|---|---|---|
| The timer branch wins race | Outer result: timeout | Underlying fetch cancelled |
| Original response gate is released | Original fetch reads done | Timeout means all work stopped |
| A separate signalled request is aborted | Client AbortError; connection closure observed | Server writes rolled back |
Wire cancellation to the request
The AbortSignal documentation shows how the signal is associated with a request. Creating a controller without passing its signal does not make that association. This reference structure manages only its own deadline timer; it does not implement user cancellation, concurrency control or retries.
async function readWithDeadline(url, milliseconds) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), milliseconds);
try {
const response = await fetch(url, { signal: controller.signal });
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return await response.text();
} finally {
clearTimeout(timer);
}
}A disconnected client does not settle server state
In the second local case, the editor deliberately advanced an in-memory server task counter after client abort; it still reached 1. That authored server behavior demonstrates why connection state alone cannot establish business state. No real provider job or user data was involved.
For email sending, paid generation or writes, inspect the operation ID, result record and the provider’s actual cancellation and idempotency rules before retrying. Preserve an unknown outcome rather than automatically submitting the operation again after a UI timeout.
Check errors and cleanup as well
The Fetch guide distinguishes HTTP responses from network failures. A 404 or 500 can still produce a Response, so the reference checks response.ok separately. Do not classify every failure as AbortError; an AbortSignal.timeout implementation can also produce TimeoutError.
The async forEach completion guide asks which promise is awaited. The voice-task cancellation case addresses interaction state. This article checks a request signal and server boundary; retain separate evidence for those tasks.
Include quick success, timeout, HTTP failure and a response whose headers arrive before its body finishes. Create a fresh controller for each operation and clear your timer on completion. An already-aborted signal is not reusable for the next request.


