1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(ext/file): resolve unresolved Promise in Blob.stream (#20039)

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

---
This could be a [stream spec](https://streams.spec.whatwg.org) 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:6ba245fe25/ext/web/06_streams.js (L2026)
which ends up calling `readIntoRequest.closeSteps(chunk);` in
6ba245fe25/ext/web/06_streams.js (L2070)



To reproduce:

```js
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
```
This commit is contained in:
Marcos Casagrande 2023-08-04 13:57:54 +02:00 committed by GitHub
parent 53ab6c004a
commit 5311f69bbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -366,7 +366,11 @@ class Blob {
const { value, done } = await AsyncGeneratorPrototypeNext( const { value, done } = await AsyncGeneratorPrototypeNext(
partIterator, partIterator,
); );
if (done) return controller.close(); if (done) {
controller.close();
controller.byobRequest?.respond(0);
return;
}
if (TypedArrayPrototypeGetByteLength(value) > 0) { if (TypedArrayPrototypeGetByteLength(value) > 0) {
return controller.enqueue(value); return controller.enqueue(value);
} }

View file

@ -4414,8 +4414,16 @@
"response-consume-empty.any.worker.html": [ "response-consume-empty.any.worker.html": [
"Consume empty FormData response body as text" "Consume empty FormData response body as text"
], ],
"response-consume-stream.any.html": false, "response-consume-stream.any.html": [
"response-consume-stream.any.worker.html": false, "Read text response's body as readableStream with mode=byob",
"Read URLSearchParams response's body as readableStream with mode=byob",
"Read array buffer response's body as readableStream with mode=byob"
],
"response-consume-stream.any.worker.html": [
"Read text response's body as readableStream with mode=byob",
"Read URLSearchParams response's body as readableStream with mode=byob",
"Read array buffer response's body as readableStream with mode=byob"
],
"response-init-contenttype.any.html": true, "response-init-contenttype.any.html": true,
"response-init-contenttype.any.worker.html": true, "response-init-contenttype.any.worker.html": true,
"response-static-json.any.html": true, "response-static-json.any.html": true,
@ -5770,8 +5778,8 @@
"Blob-slice-overflow.any.worker.html": true, "Blob-slice-overflow.any.worker.html": true,
"Blob-slice.any.html": true, "Blob-slice.any.html": true,
"Blob-slice.any.worker.html": true, "Blob-slice.any.worker.html": true,
"Blob-stream.any.html": false, "Blob-stream.any.html": true,
"Blob-stream.any.worker.html": false, "Blob-stream.any.worker.html": true,
"Blob-text.any.html": true, "Blob-text.any.html": true,
"Blob-text.any.worker.html": true, "Blob-text.any.worker.html": true,
"Blob-in-worker.worker.html": true, "Blob-in-worker.worker.html": true,