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/file): resolve unresolved Promise in Blob.stream #20039

Merged
merged 5 commits into from
Aug 4, 2023

Conversation

marcosc90
Copy link
Contributor

This PR fixes some crashing WPT tests due to an unresolved promise.


This could be a stream spec bug

When controller.close is called on a byob stream, there's no cleanup of pending readIntoRequests. The only cleanup of pending readIntoRequests happen when .byobRequest.respond(0) is called, it happens here:

function readableByteStreamControllerRespondInClosedState(
which ends up calling readIntoRequest.closeSteps(chunk); in
readableStreamFulfillReadIntoRequest(stream, filledView, done);

To reproduce:

async function byobRead() {
  const input = [new Uint8Array([8, 241, 48, 123, 151])];
  const stream = new ReadableStream({
    type: "bytes",
    async pull(controller) {
      if(input.length === 0) {
        controller.close();
        // controller.byobRequest.respond(0); // uncomment for fix 
        return 
      }
      controller.enqueue(input.shift())
    },
  });

  const reader = stream.getReader({ mode: 'byob' });
  const r1 = await reader.read(new Uint8Array(64));
  console.log(r1);
  const r2 = await reader.read(new Uint8Array(64));
  console.log(r2);
}

await byobRead();

Running the script triggers:

error: Top-level await promise never resolved

@marcosc90
Copy link
Contributor Author

A few more fetch tests were enabled: response-consume-stream.any.html & response-consume-stream.any.worker.html

test Getting an error Response stream ... ok
test Getting a redirect Response stream ... ok
test Read empty text response's body as readableStream ... ok
test Read empty blob response's body as readableStream ... ok
test Read blob response's body as readableStream with mode=undefined ... ok
test Read text response's body as readableStream with mode=undefined ... ok
test Read URLSearchParams response's body as readableStream with mode=undefined ... ok
test Read array buffer response's body as readableStream with mode=undefined ... ok
test Read form data response's body as readableStream with mode=undefined ... ok
test Read blob response's body as readableStream with mode=byob ... ok
test Read text response's body as readableStream with mode=byob ... failed (expected)
test Read URLSearchParams response's body as readableStream with mode=byob ... failed (expected)
test Read array buffer response's body as readableStream with mode=byob ... failed (expected)
test Read form data response's body as readableStream with mode=byob ... ok

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, great fix. Thank you @marcosc90!

@bartlomieju bartlomieju merged commit 5311f69 into denoland:main Aug 4, 2023
12 checks passed
@marcosc90 marcosc90 deleted the fix-byob-reader branch August 4, 2023 12:05
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.

2 participants