-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream.Duplex.from
with rejecting promise leads to uncaught exception
#46071
Comments
It doesn't require an external library, this is a reproducible example:
I'll try to fix it |
The problem originates from using an Iterable that contains Promises.
When executing node/lib/internal/streams/from.js Lines 83 to 110 in 6668c4d
At line 93 while the loop is blocked awaiting the first promise, the timeout of the second promise is over and the callback is executed. Since the loop is still blocked on the first promise, the second promise rejects without a handler and results in uncaught exception. |
@nodejs/streams Do you think we should document this somewhere? Seems to be a "Broken Promises" problem rather than a specific stream problem. |
I think we should document this behavior as a caveat. The current behavior is correct, even if it's surprising. |
@mcollina I could add a note in the documentation of Duplex.from and Readable.from warning that the use of array with promises leds to uncaught exceptions |
Go for it. |
PR-URL: nodejs#46135 Fixes: nodejs#46071 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Version
v16.19.0, v19.3.0
Platform
Darwin Simens-MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64
Subsystem
stream
What steps will reproduce the bug?
If passing an array of Promises to
stream.Duplex.from
and one rejects before all others are settled, an uncaught error is emitted. If all promises except for the rejected one are settled, then it correctly emits an error event on the stream instead.get-stream
: https://www.npmjs.com/package/get-stream (I don't know a good way with corestream
to get a promise of a stream).How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
There should never be an uncaught error, it should always be emitted as an error event on the stream.
What do you see instead?
Uncaught error emitted.
Additional information
No response
The text was updated successfully, but these errors were encountered: