Version
main
Platform
Subsystem
stream
What steps will reproduce the bug?
import{setTimeout}from'node:timers/promises';import{broadcast}from'node:stream/iter';const{ writer,broadcast: bc}=broadcast({budget: 16384,backpressure: 'unbounded',});constreader=bc.push()[Symbol.asyncIterator]();awaitwriter.write(newUint8Array(16384));constpendingWrite=writer.write(Uint8Array.of(1));constendPromise=writer.end();console.log('first read done:',(awaitreader.next()).done);constwriteState=awaitPromise.race([pendingWrite.then(()=>'resolved',()=>'rejected',),setTimeout(100,'still pending'),]);console.log('blocked write:',writeState);console.log('second read done:',(awaitreader.next()).done);console.log('final read done:',(awaitreader.next()).done);console.log('end():',awaitendPromise);How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
first read done: falseblocked write: resolvedsecond read done: falsefinal read done: trueend(): 16385
Writes queued before end() should remain ahead of end-of-stream. The pending write should be promoted when the first read frees capacity, and end() should resolve only after the consumer reaches the final end sentinel.
As per §7.2.2, Writer.write():
“return a promise that resolves when the batch is transferred to the slots buffer.”
And §7.2.5, Writer.end() / Writer.endSync():
“signals end-of-stream and waits for buffered data to drain.”
What do you see instead?
first read done: falseblocked write: still pendingsecond read done: truefinal read done: trueend(): 16384
After end() marks the broadcast ended, freeing buffer capacity cannot promote the queued write. Its promise remains pending, the byte is never delivered, and end() reports only the first write.
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?
Writes queued before
end()should remain ahead of end-of-stream. The pending write should be promoted when the first read frees capacity, andend()should resolve only after the consumer reaches the final end sentinel.As per §7.2.2,
Writer.write():And §7.2.5,
Writer.end()/Writer.endSync():What do you see instead?
After
end()marks the broadcast ended, freeing buffer capacity cannot promote the queued write. Its promise remains pending, the byte is never delivered, andend()reports only the first write.Additional information
No response