Skip to content

Fix respond() leaving bytes queued behind a pending read() - #1393

Open
MattiasBuelens wants to merge 1 commit into
whatwg:mainfrom
MattiasBuelens:respond-detached-pull-into-pending-read
Open

MattiasBuelens wants to merge 1 commit into
whatwg:mainfrom
MattiasBuelens:respond-detached-pull-into-pending-read

Conversation

@MattiasBuelens

@MattiasBuelens MattiasBuelens commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

ReadableByteStreamControllerRespondInReadableState() moves the bytes written into a detached pull-into descriptor to the queue, and then fills any pending pull-into descriptors from it. However, we also need to fill any pending read() requests, since a default reader doesn't have a pull-into descriptor when there's no autoAllocateChunkSize. This left the read() pending forever, even though the stream does have bytes for it in its queue.

Fix it by also processing the read requests in this scenario, after processing the pull-into descriptors (so with autoAllocateChunkSize, the queued bytes still go into the buffer allocated for that read()).

Fixes #1390.

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


Preview | Diff

ReadableByteStreamControllerRespondInReadableState() moves the bytes
written into a detached pull-into descriptor to the queue, and then fills
any pending pull-into descriptors from it. Nothing fills pending read
requests, so a default reader with no autoAllocateChunkSize has no
descriptor to absorb the bytes and its read() never settles, even though
the bytes it needs are sitting in the queue.

Process the read requests as well, after the pull-into descriptors.
Doing it in that order keeps the auto-allocated descriptor of a default
reader in play: with autoAllocateChunkSize the queued bytes are copied
into that descriptor, so the chunk is still backed by the buffer that was
allocated for that read(), and the queue is drained before the read
requests are considered.

Fixes whatwg#1390.

@shannonbooth shannonbooth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

spec change and test looks good to me, hopefully implementors express interest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Default read hangs after BYOB releaseLock() and respond()

2 participants