Skip to content

stream/iter consumers do not reject on abort while async iterator is pending #64065

Description

@trivikr

Version

main

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import {
  array,
  arrayBuffer,
  bytes,
  text,
} from 'node:stream/iter';
import { setTimeout } from 'node:timers/promises';

async function* never() {
  await new Promise(() => {});
}

async function check(name, fn) {
  const ac = new AbortController();

  setTimeout(10).then(() => ac.abort(new Error('boom')));

  const result = await Promise.race([
    fn(never(), { signal: ac.signal })
      .then(() => `${name} resolved`)
      .catch((err) => `${name} rejected: ${err.message}`),
    setTimeout(80, `${name} timeout`),
  ]);

  console.log(result);
}

await check('bytes', bytes);
await check('text', text);
await check('arrayBuffer', arrayBuffer);
await check('array', array);

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

Always

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

bytes rejected: boom
text rejected: boom
arrayBuffer rejected: boom
array rejected: boom

What do you see instead?

bytes timeout
text timeout
arrayBuffer timeout
array timeout

All four consumers accept { signal }, but aborting the signal does not settle the operation while the source’s async iterator is stuck in a pending next(). They should reject promptly with the abort reason instead of waiting for another batch to arrive.

Additional information

No response

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to the stream subsystem.

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