stream: `pipeTo` with `preventCancel` can hit `ERR_INTERNAL_ASSERTION` if destination errors before deferred write
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
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 https://github.com/nodejs/node/pull/61800.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied reproduction on v24.16.0 and compare it with v24.14.1. Inspect node:internal/webstreams/writablestream at line 982 and node:internal/webstreams/readablestream at line 1677, then review PR #61800; done means a regression test confirms preventCancel rejects with the destination error instead of ERR_INTERNAL_ASSERTION.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100