Skip to content

stream/iter: merge() does not abort pending read for a single source #64444

Description

@trivikr

Version

main

Platform

macOS 26.5.2

Subsystem

stream

What steps will reproduce the bug?

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

const source = {
  [Symbol.asyncIterator]() { return this; },
  next() { return new Promise(() => {}); },
  return() {
    console.log('source closed');
    return { done: true };
  },
};

const iterator = merge(source, {
  signal: AbortSignal.timeout(10),
})[Symbol.asyncIterator]();

console.log(await Promise.race([
  iterator.next().then(null, (error) => error.name),
  setTimeout(100, 'still pending'),
]));

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

Always

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

source closed
TimeoutError

As per §12.2 Stream.merge()

On cancellation (via signal or consumer break), call .return() on all active iterators and discard ready.

What do you see instead?

still pending

The pending merged read remains unsettled and source closed is never printed

Additional information

No response

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to the stream subsystem.

Type

No type

Fields

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