Skip to content

Promise version of stream.finished does not give access to cleanup function #42938

Description

@kwasimensah

Version

16.13.0

Platform

Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64

Subsystem

streams

What steps will reproduce the bug?

const readStream = fs.createReadStream(<a folder>)
const writeStream = fs.createWriteStream("foo.txt")

readStream.on("error", (error) => {
   throw new errlop('Caught the error', error)'
})

readStream.pipe(writeStream);
await stream.finished(writeStream);

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

Always reproduces

What is the expected behavior?

await stream.finished(writeStream) returns the cleanup function specified at https://nodejs.org/docs/latest-v16.x/api/stream.html#streamfinishedstream-options-callback so we can clean up the error call.

Or that error rejects the promise we're awaiting on and gets treated as part of the normal Promise error handling flow.

What do you see instead?

"Uncaught Error: Caught the error"

Additional information

https://github.com/nodejs/node/blob/master/lib/internal/streams/end-of-stream.js#L242 drops the cleanup function that eos returns.

I think I can work around this by manually making my own promises that resolve/reject based on callbacks firing

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions