[whatwg/streams] ReadableStreamClose with async iterator and pending read requests errors (#1100)

In implementing the Streams spec in Deno, I came across a regression that I think might be a spec error.  We had a test which attempted to close an async iterable on a `ReadableStream` before all the reads had completed (reading a body returned from fetch).

According to the [spec for `ReadableStreamClose`](https://streams.spec.whatwg.org/#readable-stream-close), for a `ReadableStreamDefaultReader` any pending read requests close steps should be performed (5.1.1) before resolving the `reader.[[closedPromise]]`.

The [read request from an iterators next steps](https://streams.spec.whatwg.org/#readablestream-async-iterator-reader) set the closed steps to call [`ReadableStreamReaderGenericRelease`](https://streams.spec.whatwg.org/#readable-stream-reader-generic-release), which will reject the closed promise (either step 3 or 4).

That means when we get to step 6 of `ReadableStreamClose` the promise is already fulfilled, which in the case of our implementation threw an error.  I have added a guard step to determine if the `[[closedPromised]]` is already fulfilled at step 6, but I don't know if that is the best long term solution, or if I have some other mis-understanding about the spec, where it should be impossible for the `[[closedPromise]]` to already be settled that that step.



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1100

Received on Tuesday, 12 January 2021 22:13:20 UTC