Skip to content

stream/iter: merge() proactively drains fast sources while merged consumer is idle #63566

Description

@trivikr

Version

26.2.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { merge } from 'node:stream/iter';
import { setTimeout as sleep } from 'node:timers/promises';

function source(n) {
  return {
    pulls: 0,
    async *[Symbol.asyncIterator]() {
      while (this.pulls < n) yield [Buffer.from(`${++this.pulls}`)];
    },
  };
}

const a = source(5);
const b = source(5);
const it = merge(a, b)[Symbol.asyncIterator]();

await it.next();
await sleep(20);

console.log({ a: a.pulls, b: b.pulls });
await it.return?.();

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

Always

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

after only one await it.next() from the merged iterator, both sources should not be pulled to completion while the merged consumer is idle.

What do you see instead?

{ a: 5, b: 5 }

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to Node.js streams.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions