Version
main
Platform
Subsystem
stream
What steps will reproduce the bug?
import{share}from'node:stream/iter';letbatchesYielded=0;asyncfunction*source(){for(leti=0;i<7;i++){batchesYielded++;console.log('source yielded',i);yield[newUint8Array(16_384).fill(i)];}}constshared=share(source(),{budget: 16_384,backpressure: 'drop-newest',});constfast=shared.pull()[Symbol.asyncIterator]();conststalled=shared.pull();letresult=awaitfast.next();console.log('after first next',{done: result.done,firstByte: result.value?.[0][0],
batchesYielded,});constsecond=fast.next();awaitnewPromise(setImmediate);console.log('batches after one event-loop turn:',batchesYielded);shared.cancel();console.log('second next:',awaitsecond);voidstalled;How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
source yielded 0after first next { done: false, firstByte: 0, batchesYielded: 1 }source yielded 1batches after one event-loop turn: 2second next: [Object: null prototype] { done: true, value: undefined }The second fast.next() should discard only one upstream result and then wait for buffer space. shared.cancel() subsequently settles that pending call so the repro exits cleanly.
From §13.2.2: Share buffering and backpressure:
“With "drop-newest", the upstream pull result is discarded.”
What do you see instead?
source yielded 0after first next { done: false, firstByte: 0, batchesYielded: 1 }source yielded 1source yielded 2source yielded 3source yielded 4source yielded 5source yielded 6batches after one event-loop turn: 7second next: [Object: null prototype] { done: true, value: undefined }One fast.next() pulls and discards all six remaining batches while the buffer is full.
Additional information
No response
Version
main
Platform
Subsystem
stream
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
The second
fast.next()should discard only one upstream result and then wait for buffer space.shared.cancel()subsequently settles that pending call so the repro exits cleanly.From §13.2.2: Share buffering and backpressure:
What do you see instead?
One
fast.next()pulls and discards all six remaining batches while the buffer is full.Additional information
No response