Skip to content

stream/iter: zero-byte broadcast writes bypass backpressure and grow buffer unbounded #64771

Description

@trivikr

Version

main

Platform

macOS 26.5.2

Subsystem

stream

What steps will reproduce the bug?

import { broadcast } from 'node:stream/iter';

const { writer, broadcast: channel } = broadcast({
  budget: 16_384,
  backpressure: 'strict',
});
const readable = channel.push();

let accepted = 0;
while (accepted < 100_000 && writer.writevSync([])) accepted++;

console.log({ accepted, canWrite: writer.canWrite });

await writer.end();

let entries = 0;
for await (const _ of readable) entries++;

console.log({ entries });

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

{ accepted: 100000, canWrite: true }
{ entries: 0 }

Zero-byte writes should be accepted as no-ops and create no buffer entries, preventing unbounded growth.

From specification §13.1.2 Broadcast backpressure

The shared buffer cannot overwrite entries that the slowest consumer has not yet read.

What do you see instead?

{ accepted: 100000, canWrite: true }
{ entries: 100000 }

All 100,000 empty batches are buffered.

Additional information

No response

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to the stream subsystem.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions