Skip to content

stream/iter: share() does not serialize overlapping next() calls on a consumer #63477

Description

@trivikr

Version

26.2.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

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

async function* source() {
  yield [new TextEncoder().encode('first')];
  yield [new TextEncoder().encode('second')];
}

const decoder = new TextDecoder();
const it = share(source()).pull()[Symbol.asyncIterator]();

const p1 = it.next();
const p2 = it.next();

const [r1, r2] = await Promise.all([p1, p2]);

console.log('p1:', decoder.decode(r1.value[0]));
console.log('p2:', decoder.decode(r2.value[0]));

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

Always

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

p1: first
p2: second

p1 is the earlier next() call on the same async iterator, so it should resolve with the earlier chunk.

What do you see instead?

p1: second
p2: first

Additional information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions