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

Discard auto-allocated BYOB request on enqueue #1171

Conversation

MattiasBuelens
Copy link
Collaborator

@MattiasBuelens MattiasBuelens commented Oct 5, 2021

As discovered in #1170 (comment): if a BYOB request was auto-allocated, but then you call controller.enqueue() instead of byobRequest.respond(), then the auto-allocated pull-into descriptor stays in the queue. If you later on switch from a default reader to a BYOB reader, you run into trouble because the list of read-into requests no longer matches up with the list of pending pull-into descriptors.

This PR fixes it by making enqueue() discard that auto-allocated BYOB request.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

Copy link
Collaborator

@ricea ricea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

index.bs Outdated
@@ -3136,6 +3136,13 @@ The following abstract operations support the implementation of the
[$TransferArrayBuffer$](|firstPendingPullInto|'s [=pull-into descriptor/buffer=]).
1. Perform ! [$ReadableByteStreamControllerInvalidateBYOBRequest$](|controller|).
1. If ! [$ReadableStreamHasDefaultReader$](|stream|) is true
1. If |controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=] is not
[=list/is empty|empty=],
1. Assert: |controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=]'s [=list/size=]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to think about this for a while to understand why it was true. Could you perhaps add a note explaining it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hang on... this is wrong. Every call to ReadableStreamDefaultReader.read() creates a new pull-into descriptor, regardless of whether we can pull() again. For example, this creates two such descriptors:

let controller;
const stream = new ReadableStream({
  start(c) {
    controller = c;
  },
  type: 'bytes',
  autoAllocateChunkSize: 16
}, {
  highWaterMark: 0
});

const reader = stream.getReader();
const read1 = reader.read();
const read2 = reader.read();

What is true is that, if autoAllocateChunkSize is not undefined, then the length of [[pendingPullIntos]] matches that of [[readRequests]]. So we need to remove only the first descriptor on enqueue().

@ricea
Copy link
Collaborator

ricea commented Oct 7, 2021

Chrome is interested in this (I'm in the middle of implementing it).

@ricea
Copy link
Collaborator

ricea commented Oct 7, 2021

Implementation bug for Chrome: https://crbug.com/1257465.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 7, 2021
Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 7, 2021
Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 7, 2021
Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3211027
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929119}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 7, 2021
Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3211027
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929119}
blueboxd pushed a commit to blueboxd/chromium-legacy that referenced this pull request Oct 7, 2021
Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3211027
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929119}
There *can* be more than one auto-allocated pull-into descriptor.
@MattiasBuelens
Copy link
Collaborator Author

@ricea I'm afraid you're going to have to re-open that Chromium bug. We assumed that there'd only be one auto-allocated pull-into descriptor, but that's not correct.

@ricea
Copy link
Collaborator

ricea commented Oct 8, 2021

@ricea I'm afraid you're going to have to re-open that Chromium bug. We assumed that there'd only be one auto-allocated pull-into descriptor, but that's not correct.

Thanks for looking at it again! I am updating the fix in Chromium.

@domenic
Copy link
Member

domenic commented Oct 12, 2021

Tests are merged so you can roll them and then we can merge this PR.

Can you also file a WebKit bug? They appear to have a BYOB stream implementation on their main branch, at least. Firefox is still missing byte stream support.

@MattiasBuelens
Copy link
Collaborator Author

Implementation bugs filed.

Do we need to ask for implementer interest from the WebKit folks? Since this is more of a bug fix, I guess it's not that critical.

@domenic
Copy link
Member

domenic commented Oct 12, 2021

Yeah, for a bug fix I'm OK just merging as-is.

@domenic domenic merged commit 02de71a into whatwg:main Oct 12, 2021
@MattiasBuelens MattiasBuelens deleted the discard-auto-allocated-byob-request-on-enqueue branch October 12, 2021 22:54
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Oct 14, 2021
…eue(), a=testonly

Automatic update from web-platform-tests
ReadableStream: Fix respond() after enqueue()

Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3211027
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929119}

--

wpt-commits: 73ff424533dc6b1277ab978b3be72cafebf7299c
wpt-pr: 31145
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Oct 14, 2021
…eue(), a=testonly

Automatic update from web-platform-tests
ReadableStream: Fix respond() after enqueue()

Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3211027
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929119}

--

wpt-commits: 73ff424533dc6b1277ab978b3be72cafebf7299c
wpt-pr: 31145
Gabisampaio pushed a commit to Gabisampaio/wpt that referenced this pull request Nov 18, 2021
Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3211027
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929119}
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this pull request Oct 14, 2022
Calling respond() after enqueue() on a readable byte stream when
autoAllocateChunkSize was in use would cause a crash.

Fix it by applying the change from
whatwg/streams#1171.

Fixed: 1255762,1257465
Change-Id: Ic770e79878fb9f6363e55f8104ec0bacab0e60c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3211027
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929119}
NOKEYCHECK=True
GitOrigin-RevId: 55317e09879898c8f6d2e1c010f5b567dd4d474c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants