-
Notifications
You must be signed in to change notification settings - Fork 161
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
Support teeing readable byte streams #1114
Conversation
18544b8
to
e3c2532
Compare
158d02e
to
7f3fdc9
Compare
Previously, if you cancel the stream while a BYOB read is pending, the stream has to wait for the underlying byte source to call respond(0) before it can return the BYOB request's buffer to the caller. This makes underlying byte sources difficult to write in a robust way. After this change, the contract changes so that canceling a stream while a BYOB read is pending will always lead to the stream not giving you back your buffer. This means that cancel() can immediately resolve all pending BYOB reads with the classic { done: true, value: undefined }, without having to wait for the underlying byte source. This solves the problem, and would make it easier to implement an underlying byte source. To make this work, an additional change was required: when the stream is canceled, any pending BYOB request is now immediately invalidated, so the underlying byte source doesn't erroneously think that it still needs to provide a response. (This aligns with the behavior of controller.enqueue(), which throws if the stream is already closed.) See #1114 (comment) and #1123 (comment) for some discussion and background.
8aa1316
to
b4424f2
Compare
Previously, if you cancel the stream while a BYOB read is pending, the stream has to wait for the underlying byte source to call respond(0) before it can return the BYOB request's buffer to the caller. This makes underlying byte sources difficult to write in a robust way. After this change, the contract changes so that canceling a stream while a BYOB read is pending will always lead to the stream not giving you back your buffer. This means that cancel() can immediately resolve all pending BYOB reads with the classic { done: true, value: undefined }, without having to wait for the underlying byte source. This solves the problem, and would make it easier to implement an underlying byte source. To make this work, an additional change was required: when the stream is canceled, any pending BYOB request is now immediately invalidated, so the underlying byte source doesn't erroneously think that it still needs to provide a response. (This aligns with the behavior of controller.enqueue(), which throws if the stream is already closed.) See whatwg#1114 (comment) and whatwg#1123 (comment) for some discussion and background.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits. Exciting...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked the algorithms and cross-referenced against the reference implementation and it all looks good.
I haven't analysed it for re-entrancy risk. I'm a bit worried about that.
70dee35
to
296c901
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added handling for errors from cloning chunks.
Still gotta find some time to write tests for all these edge cases. 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec looks good to me at this point! I guess the new error cases, including for non-byte tee() are testable (although probably not in the reference implementation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Not sure why the bots are failing; try rebasing? That was the wrong PR.
@ricea feel free to take a look
Yay! 🥳 I assume this means Chrome is interested in implementing? I'll go ahead and file an implementation bug then. 🙂 |
Yes, Chrome is interested. |
…streams, a=testonly Automatic update from web-platform-tests Streams: tests for teeing readable byte streams Follows whatwg/streams#1114. -- wpt-commits: 87a4c80598aee5178c385628174f1832f5a28ad6 wpt-pr: 29190
…streams, a=testonly Automatic update from web-platform-tests Streams: tests for teeing readable byte streams Follows whatwg/streams#1114. -- wpt-commits: 87a4c80598aee5178c385628174f1832f5a28ad6 wpt-pr: 29190
…streams, a=testonly Automatic update from web-platform-tests Streams: tests for teeing readable byte streams Follows whatwg/streams#1114. -- wpt-commits: 87a4c80598aee5178c385628174f1832f5a28ad6 wpt-pr: 29190
…streams, a=testonly Automatic update from web-platform-tests Streams: tests for teeing readable byte streams Follows whatwg/streams#1114. -- wpt-commits: 87a4c80598aee5178c385628174f1832f5a28ad6 wpt-pr: 29190
This CL implements teeing support for readable byte streams, so that teeing a byte stream creates two readable byte streams instead of two default readable streams. The corresponding spec change was done in whatwg/streams#1114. Bug: 1227496 Change-Id: Ica29d939b7b3a3f7d6086b42ee1e8a538b611b25 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3757034 Commit-Queue: Nidhi Jaju <[email protected]> Reviewed-by: Adam Rice <[email protected]> Cr-Commit-Position: refs/heads/main@{#1128460}
With this PR, teeing a readable byte stream will now create two readable byte streams (instead of two "default" readable streams). See #1111 for context.
This implements the "hard" solution: when a branch is being read using a BYOB reader, the view of that read request is forwarded to the original stream, so it can read directly into that view. After the view is filled, an identical copy is created and enqueued on the other branch, so they both see the same data.
To do:
@ricea
)(See WHATWG Working Mode: Changes for more details.)
Preview | Diff