Skip to content

Potentially wrong docs in readable.pipe(destination) about not cleaning up writable #46908

@zbjornson

Description

@zbjornson

Affected URL(s)

https://nodejs.org/dist/latest-v16.x/docs/api/stream.html#readablepipedestination-options

Description of the problem

The linked docs say:

One important caveat is that if the Readable stream emits an error during processing, the Writable destination is not closed automatically. If an error occurs, it will be necessary to manually close each stream in order to prevent memory leaks.

It seems like it does close/destroy the writable. See below test. I can't find any tests that assert that it's not closed.

import stream from "node:stream";
import {finished} from "node:stream/promises";
import assert from "node:assert";

class NullWritable extends stream.Writable {
	_write(c, e, cb) { cb(); }
}

const src = stream.Readable.from(["1", "2", "3"]);
const dest = new NullWritable();
const theError = new Error("aborted");
src.pipe(dest);
process.nextTick(() => src.emit("error", theError)); // Emit an error during processing
await assert.rejects(finished(src));
assert.strictEqual(src.destroyed, true);
assert.strictEqual(dest.destroyed, false); // This is true; docs suggest it would be false

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.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