Skip to content

stream/iter: Writer.end() ignores AbortSignal #64726

Description

@trivikr

Version

main

Platform

macOS 26.5.2

Subsystem

stream

What steps will reproduce the bug?

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

async function repro(label, abortBeforeEnd) {
  const { writer, readable } = push();
  await writer.write('x');

  const controller = new AbortController();
  if (abortBeforeEnd) controller.abort(new Error('stop'));

  const ending = writer.end({ signal: controller.signal }).then(
    (bytes) => `resolved: ${bytes}`,
    (error) => `rejected: ${error.message}`,
  );

  if (!abortBeforeEnd) controller.abort(new Error('stop'));

  const draining = (async () => {
    for await (const chunk of readable) {
      void chunk;
    }
  })();

  console.log(`${label}: ${await ending}`);
  await draining;
}

await repro('pre-aborted', true);
await repro('aborted while draining', false);

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

Always

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

it should reject with the signal’s abort reason in both cases.

What do you see instead?

pre-aborted: resolved: 1
aborted while draining: resolved: 1

end() resolves successfully whether the signal is already aborted or becomes aborted while the buffered data is draining.

Additional information

No response

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to the stream subsystem.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions