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, 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 set the closed steps to call ReadableStreamReaderGenericRelease, 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.
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
ReadableStreambefore all the reads had completed (reading a body returned from fetch).According to the spec for
ReadableStreamClose, for aReadableStreamDefaultReaderany pending read requests close steps should be performed (5.1.1) before resolving thereader.[[closedPromise]].The read request from an iterators next steps set the closed steps to call
ReadableStreamReaderGenericRelease, which will reject the closed promise (either step 3 or 4).That means when we get to step 6 of
ReadableStreamClosethe 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.