Skip to content

stream/iter: broadcast consumer can leave earlier next() pending after overlapping next() calls #63499

@trivikr

Description

@trivikr

Version

26.2.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

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

const { writer, broadcast: bc } = broadcast();
const it = bc.push()[Symbol.asyncIterator]();

const first = it.next();
const second = it.next();

await writer.write('x');

console.log('second next():', await second);

const result = await Promise.race([
  first.then((value) => ['settled', value]),
  new Promise((resolve) => setTimeout(resolve, 50, ['pending'])),
]);

console.log('first next():', ...result);

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

Always

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

second next(): { done: true, value: undefined }
first next(): settled { done: false, value: [ Uint8Array(1) [ 120 ] ] }

What do you see instead?

second next(): { done: false, value: [ Uint8Array(1) [ 120 ] ] }
first next(): pending

Additional information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions