Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch abort active streaming upload should cancel ReadableStream #41891

Open
campersau opened this issue Sep 8, 2023 · 1 comment
Open

Fetch abort active streaming upload should cancel ReadableStream #41891

campersau opened this issue Sep 8, 2023 · 1 comment
Labels

Comments

@campersau
Copy link

Since we have now half duplex streaming uploads should there also be a test where the AbortController gets aborted after the call to fetch? The asserts should still be the same right?

promise_test(async t => {
const controller = new AbortController();
const signal = controller.signal;
controller.abort();
let cancelReason;
const body = new ReadableStream({
pull(controller) {
controller.enqueue(new Uint8Array([42]));
},
cancel(reason) {
cancelReason = reason;
}
});
const fetchPromise = fetch('../resources/empty.txt', {
body, signal,
method: 'POST',
duplex: 'half',
headers: {
'Content-Type': 'text/plain'
}
});
assert_true(!!cancelReason, 'Cancel called sync');
assert_equals(cancelReason.constructor, DOMException);
assert_equals(cancelReason.name, 'AbortError');
await promise_rejects_dom(t, "AbortError", fetchPromise);
const fetchErr = await fetchPromise.catch(e => e);
assert_equals(cancelReason, fetchErr, "Fetch rejects with same error instance");
}, "Readable stream synchronously cancels with AbortError if aborted before reading");

It looks like browsers don't support the current test as they don't cancel the ReadableStream and cancelReason is not set.
I think the don't even touch the ReadableStream in this case as it isn't locked which I kind of get.
But when an active streaming upload gets cancelled the ReadableStream should always be canceled, as it is locked by the browser.

See also https://bugs.chromium.org/p/chromium/issues/detail?id=1480250

@campersau
Copy link
Author

In addition to only cancel the ReadableStream on abort it would also be useful if the ReadableStream got cancelled when fetch fails due to network issues, cors, HTTP1, or anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants