Skip to content

stream: pipeTo with preventCancel can hit ERR_INTERNAL_ASSERTION if destination errors before deferred write #63732

Description

@colinaaa

Version

v24.16.0

Platform

Linux n37-114-192 5.15.120.bsk.3-amd64 #5.15.120.bsk.3 SMP Debian 5.15.120.bsk.3 Fri Dec 8 12:41:09 UTC x86_64 GNU/Linux

Subsystem

stream

What steps will reproduce the bug?

const { ReadableStream, WritableStream } = require("node:stream/web");

let sourceController;
let destController;

const source = new ReadableStream({
  start(controller) {
    sourceController = controller;
  },
});

const dest = new WritableStream({
  start(controller) {
    destController = controller;
  },
  write() {},
});

source.pipeTo(dest, { preventCancel: true }).catch((err) => {
  console.log("pipeTo rejected:", err.name, err.message);
});

setImmediate(() => {
  destController.error(new Error("destination errored"));
  sourceController.enqueue("chunk");
});

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

Always.

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

pipeTo() should reject with the destination error, like v24.14.1 does:

pipeTo rejected: Error destination errored

What do you see instead?

node:internal/assert:11
    throw new ERR_INTERNAL_ASSERTION(message);
          ^

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at assert (node:internal/assert:11:11)
    at writableStreamDefaultWriterWrite (node:internal/webstreams/writablestream:982:3)
    at node:internal/webstreams/readablestream:1677:33
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Node.js v24.16.0

Additional information

The error starts to occur in v24.15.0. This lines up strongly with #61800.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions