A rejected fetch() promise does not tell you whether the server changed anything.
In a small local experiment, the client received AbortError, the server noticed the disconnected response, and the server's simulated write still completed. Adding a server cancellation handler prevented pending work. Moving the write earlier made cancellation too late.
Those three outcomes can look identical in a client log.
The result worth testing
Five scenarios ran five times each. Every run asserted both the client outcome and the final server counter: 25 scenario checks passed.
Here, “commit” means incrementing an in-memory counter. It does not mean a database transaction.
| Scenario | Client result | Final simulated commits per run |
|---|---|---|
| No cancellation (control) | ok | 1 |
Promise.race() deadline | DeadlineExceeded | 1 |
| Abort fetch; server ignores cancellation | AbortError | 1 |
| Abort fetch; server cancels pending work | AbortError | 0 |
| Server commits first; then handles cancellation | AbortError | 1 |
All five repetitions produced these outcomes. This is a behavioral check, not a latency benchmark or an estimate of real-world failure rates.
The setup used Node.js v24.22.1, macOS/Darwin 25.5.0, arm64, and loopback HTTP on 18 November 2026. The tests ran in a managed Node execution environment; its shell executable was checked separately for the version.
The server scheduled its simulated work for 200 ms. The client scheduled cancellation for 50 ms after the server acknowledged receipt inside the harness. Starting the timer there deliberately excludes connection setup and ensures the request has reached the handler. These are configured timer delays, not measured timing guarantees.
One error, three different server states
These are actual event sequences from the first test round.
Client abort without server cooperation:
server: received client: AbortError server: response closed early server: committed Client abort with cancellation of pending server work:
server: received client: AbortError server: response closed early server: cancelled pending work Commit before cancellation:
server: received server: committed client: AbortError server: response closed early server: cancelled pending work In the last case, the remaining delayed response was cancelled. The earlier counter increment remained.
A client-only assertion such as “the request rejected with AbortError” passes in all three cases. It cannot distinguish a prevented operation from one that completed.
Where Promise.race stops helping
Promise.race() settles from the first input that settles. The ECMAScript algorithm attaches fulfillment and rejection handlers; it does not cancel the other work.
The race scenario in this experiment supplied no abort signal to fetch. Its deadline resolved the wrapper with DeadlineExceeded, while the underlying request continued. The harness then waited for the server outcome and drained that request.
Passing an AbortSignal to fetch adds actual client-side cancellation. The Fetch standard specifies rejection and cancellation/error handling for request and response bodies. It does not provide an application-level transaction rollback on the remote server.
That is why “add AbortController” fixes only part of the problem.
The server change that altered the outcome
This is the cancellation branch from the tested handler:
res.once('close', () => { if (!res.writableEnded) { clearTimeout(work); releaseFinished(); } }); The full harness adds event logging and runs this branch only in the cooperative scenarios.
Node documents that a ServerResponse close event can mean either completion or premature connection termination. The guard distinguishes the premature-close path for this particular handler. It is not proof of a user's intention to cancel: network failures can close connections too.
Clearing a timer works here because the timer is the pending work. A real handler must use whatever cancellation mechanism its database driver, worker, subprocess, or downstream service actually supports. This experiment does not test those systems.
Also decide whether disconnecting should cancel the job at all. A disposable search request and an accepted background export may need different behavior.
Run the complete experiment
Save the following as cancellation-lab.mjs and run it in a local Node environment that permits binding a loopback port:
node --version node cancellation-lab.mjs > results.json No packages or external services are required. The output includes the environment, each event sequence, client outcomes, and server counters.
Complete harness: five scenarios, five repetitions
// cancellation-lab.mjs — synthetic loopback HTTP experiment, no dependencies. const { createServer } = await import('node:http'); const assert = (await import('node:assert/strict')).default; const os = await import('node:os'); async function runCase(mode) { const events = []; let committed = 0; let releaseReceived, releaseFinished; const received = new Promise(r => { releaseReceived = r; }); const finished = new Promise(r => { releaseFinished = r; }); const server = createServer((req, res) => { events.push('server: received'); if (mode === 'commit-first') { committed++; events.push('server: committed'); } const work = setTimeout(() => { if (mode !== 'commit-first') { committed++; events.push('server: committed'); } res.end('ok'); releaseFinished(); }, 200); res.once('close', () => { if (!res.writableEnded) { events.push('server: response closed early'); if (mode === 'cooperative' || mode === 'commit-first') { clearTimeout(work); events.push('server: cancelled pending work'); releaseFinished(); } } }); releaseReceived(); }); await new Promise((resolve, reject) => { server.once('error', reject); server.listen(0, '127.0.0.1', resolve); }); const controller = new AbortController(); let deadlineTimer; let result; try { // Attach outcome handlers immediately, including for unexpected failures. const request = fetch('http://127.0.0.1:' + server.address().port, { method: 'POST', ...(mode === 'race' || mode === 'success' ? {} : { signal: controller.signal }), }).then(r => r.text()); const observed = request.then( () => 'ok', error => error.name, ); await received; // Start deadline only once the synthetic work is accepted. if (mode === 'race') { const deadline = new Promise(resolve => { deadlineTimer = setTimeout(() => resolve('DeadlineExceeded'), 50); }); result = await Promise.race([observed, deadline]); } else { if (mode !== 'success') { deadlineTimer = setTimeout(() => controller.abort(), 50); } result = await observed; } events.push('client: ' + result); const committedAtClientResult = committed; await finished; // Inspect the server too, not just the rejected fetch. await observed; // Drain the losing request in the Promise.race case. const expected = { success: ['ok', 1], race: ['DeadlineExceeded', 1], 'abort-only': ['AbortError', 1], cooperative: ['AbortError', 0], 'commit-first': ['AbortError', 1], }[mode]; assert.equal(result, expected[0]); assert.equal(committed, expected[1]); return { mode, clientResult: result, committedAtClientResult, finalCommits: committed, events }; } finally { clearTimeout(deadlineTimer); server.closeAllConnections(); await new Promise(resolve => server.close(resolve)); } } const metadata = { date: new Date().toISOString(), node: typeof process === 'undefined' ? 'managed runtime; version not exposed' : process.version, platform: os.platform(), release: os.release(), arch: os.arch(), workload: 'synthetic in-memory counter over loopback HTTP; no database', deadlineMs: 50, serverWorkMs: 200, deadlineStarts: 'after server receives request', }; const results = []; for (let round = 1; round <= 5; round++) { for (const mode of ['success', 'race', 'abort-only', 'cooperative', 'commit-first']) { results.push({ round, ...await runCase(mode) }); } } console.log(JSON.stringify({ metadata, checksPassed: results.length, results }, null, 2)); The harness waits for server receipt before starting its deadline, and for the server outcome before checking the final counter. An unexpected failure before receipt can leave that wait pending; use your test runner's outer timeout when adapting it to CI. A heavily stalled event loop can also change scheduling. A failed assertion deserves investigation, not a new expected value chosen to make the test green.
What this does—and does not—establish
It establishes that these five deliberately constructed handlers behave differently despite similar client errors. It does not establish that your framework cancels database work, that a proxy propagates disconnects, or that any particular external API rolled back a request.
For a write endpoint, the next useful test is therefore specific: disconnect the client at controlled points, then inspect the application's recorded state. Include a case where the operation completes before the response reaches the client.
If a retry is possible, test that path separately. This harness sends no retries and makes no claim about deduplication or exactly-once execution.
The question to put next to a timeout test is: “What state remained after the caller stopped waiting?”