Skip to content

stream/iter pipeTo() does not observe abort while waiting for the next source chunk #64014

@trivikr

Description

@trivikr

Version

main

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { pipeTo } from "node:stream/iter";
import { setTimeout } from "node:timers/promises";

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

const writer = {
  write() {},
};

const ac = new AbortController();

setTimeout(100).then(() => {
  ac.abort(new Error("abort reason"));
});

const result = await Promise.race([
  pipeTo(neverYieldingSource(), writer, { signal: ac.signal }).then(
    () => "pipeTo resolved",
    (error) => `pipeTo rejected: ${error.name}: ${error.message}`,
  ),
  setTimeout(1000, "timed out"),
]);

console.log(result);

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

Always

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

pipeTo rejected: Error: abort reason

pipeTo() should reject promptly when options.signal aborts, even while waiting for the next source chunk in the no-transform path.

What do you see instead?

timed out

pipeTo() checks signal.throwIfAborted() only after for await produces a batch, so a pending source read that never settles prevents abort from being observed.

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