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

fix(ext/fetch): Properly cancel upload stream when aborting #11966

Merged
merged 7 commits into from
Sep 12, 2021

Conversation

nayeemrmn
Copy link
Collaborator

@nayeemrmn nayeemrmn commented Sep 9, 2021

Discovered bug while exploring denoland/std#1214.

const abortController = new AbortController();
await fetch(
  "https://deno.land/",
  {
    method: "POST",
    body: new ReadableStream({
      pull(controller) {
        abortController.abort();
        controller.enqueue(new Uint8Array([1, 2, 3, 4]));
      },
    }),
    signal: abortController.signal,
  },
);

main:

error: Uncaught (in promise) TypeError: Cannot cancel a locked ReadableStream.
        abortController.abort();
                        ^
    at ReadableStream.cancel (deno:ext/web/06_streams.js:3199:11)
    at InnerBody.cancel (deno:ext/fetch/22_body.js:126:29)
    at abortFetch (deno:ext/fetch/26_fetch.js:502:45)
    at ...

This PR:

error: Uncaught AbortError: Ongoing fetch was aborted.
        abortController.abort();
                        ^
    at abortFetch (deno:ext/fetch/26_fetch.js:512:19)
    at ...

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, confirmed that test fails on main. @lucacasonato any objections?

Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
@nayeemrmn nayeemrmn changed the title fix(ext/fetch): Properly cancel request body stream when aborting fix(ext/fetch): Properly cancel upload stream when aborting Sep 12, 2021
@bartlomieju bartlomieju merged commit 2cc1577 into denoland:main Sep 12, 2021
@nayeemrmn nayeemrmn deleted the fetch-abort-while-streaming branch September 17, 2021 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants