v154 · abort reason
Cancelling mid-stream
A download read chunk by chunk, ended part-way for one of four different causes, and routed on the reason. One controller, four meanings — which is why a bare AbortError at the read site was not enough.
Read a body, then stop it
- Chunks read
- 0
- Bytes
- 0
- Ended by
- —
- Reason reached the reader?
- —
How the handler routed it
Log
- Nothing yet.
The request targets /public/slow-stream, a same-origin endpoint that emits 256 KB in 8 KB pieces with a delay between them — because a real file arrives in a single chunk over localhost and there would be no mid-stream to cancel in. Everything else is ordinary: the loop reads the response body, and aborting the fetch errors that body stream so the next read() rejects with whatever the abort carried. Every one of those buttons calls abort() on the same controller. The only thing distinguishing them is the value passed in — and the only reason the handler can see it is that Chrome 154 delivers it to the stream reader rather than replacing it with a generic error.
code path
const reader = response.body.getReader();
try {
for (;;) {
const { done, value } = await reader.read();
if (done) break;
await sink.write(value);
}
} catch (error) {
switch (error?.cause) {
case "USER": return dismissQuietly();
case "QUOTA": return offerToFreeSpace();
case "NAVIGATE": return; // nobody is watching
case "STALE": return; // a newer request owns the UI
default: throw error; // a real failure
}
}