Skip to content

stream.finished throws ERR_STREAM_PREMATURE_CLOSE when it shouldn't #45281

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Tracked by #144012
watson opened this issue Nov 2, 2022 · 1 comment · Fixed by #45301
Closed
Tracked by #144012

stream.finished throws ERR_STREAM_PREMATURE_CLOSE when it shouldn't #45281

watson opened this issue Nov 2, 2022 · 1 comment · Fixed by #45301
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@watson
Copy link
Member

watson commented Nov 2, 2022

Version

17.x, 18.x, 19.x

Platform

Darwin watson.localdomain 21.6.0 Darwin Kernel Version 21.6.0: Thu Sep 29 20:13:56 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T6000 arm64

Subsystem

stream

What steps will reproduce the bug?

On Node.js 17 and newer, the program below will call the finished callback with an ERR_STREAM_PREMATURE_CLOSE error.

const { Duplex, finished } = require('stream');

const stream = new Duplex({
  write (chunk, enc, cb) {
    setImmediate(cb);
  }
});

stream.end('foo');

finished(stream, { readable: false }, (err) => {
  console.log('Finished!', { err });
});

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

Always

What is the expected behavior?

I'm not sure. For me it's unexpected and I'm not sure how to use finished in a scenario like this without getting this error.

What do you see instead?

I would expect the finished callback to be called without an error.

Additional information

As mentioned above, I'm not 100% if this is a bug or not. If it's not a bug, then the behaviour is at least unexpected and finished probably needs better documentation.

@lpinca lpinca added the stream Issues and PRs related to the stream subsystem. label Nov 2, 2022
@lpinca
Copy link
Member

lpinca commented Nov 2, 2022

cc: @ronag

ronag added a commit to nxtedition/node that referenced this issue Nov 3, 2022
nodejs-github-bot pushed a commit that referenced this issue Nov 20, 2022
Fixes: #45281
PR-URL: #45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
ruyadorno pushed a commit that referenced this issue Nov 21, 2022
Fixes: #45281
PR-URL: #45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
marco-ippolito pushed a commit to marco-ippolito/node that referenced this issue Nov 23, 2022
Fixes: nodejs#45281
PR-URL: nodejs#45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 30, 2022
Fixes: #45281
PR-URL: #45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 30, 2022
Fixes: #45281
PR-URL: #45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 3, 2023
Fixes: #45281
PR-URL: #45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 4, 2023
Fixes: #45281
PR-URL: #45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 5, 2023
Fixes: #45281
PR-URL: #45301
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants