- From: Mattias Buelens <notifications@github.com>
- Date: Mon, 04 Oct 2021 13:17:00 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/issues/1170/933822324@github.com>
We can fix this by doing `ReadableByteStreamControllerClearPendingPullIntos` in step 10. (We should probably assert that, if there are any pending pull-intos at this step, then there's exactly one and it's an auto-allocated one.) However, your test case is still invalid. After calling `enqueue()`, `c.byobRequest` is invalidated. You only get a *new* auto-allocated BYOB request after we call `pull()` again. So with the current code, `c.byobRequest` will be `null` and you'll get a "cannot read property 'respond' of null" `TypeError` instead. We need a slightly more complicated test case to properly demonstrate the bug: ```javascript promise_test(async () => { let count = 0; const rs = new ReadableStream({ type: 'bytes', autoAllocateChunkSize: 10, pull(c) { if (count === 0) { c.enqueue(new Uint8Array(10)); } else { c.byobRequest.respond(c.byobRequest.view.byteLength); } count++; } }); const reader1 = rs.getReader(); console.log(await reader1.read()); reader1.releaseLock(); const reader2 = rs.getReader({ mode: 'byob' }); console.log(await reader2.read(new Uint8Array([1, 2, 3]))); console.log('test'); }, '#1170'); ``` First, we enqueue a chunk to resolve the request from a default reader. The stream will have auto-allocated a BYOB request, but we're not using it. At this point, the stream *should* remove this pull-into descriptor from its list. Next, we start a read from a BYOB reader. At this point, this *should* have become the first pull-into descriptor, and cause the stream to call `pull()`. But since we never removed the auto-allocated descriptor, we end up in step 11 of [ReadableByteStreamControllerPullInto](https://streams.spec.whatwg.org/commit-snapshots/8bbfbf83ad06a8b9224bbe1cfbcbbbdbdd827a19/#readable-byte-stream-controller-pull-into), where we conclude that we don't need to call pull. Woops. 😛 With the proposed fix, this scenario works correctly. -- 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/1170#issuecomment-933822324
Received on Monday, 4 October 2021 20:17:13 UTC