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
Writable is destroyed before calling callback in rare case #40377
Comments
@nodejs/streams |
Don’t mix thenable with callback. |
The behavior is correct for me. After .destroy() is called, the stream is closed synchronously and no more read or write operation can happen. However the destroy cycle is asynchronous because it might take a while to completely clean up a native resource. |
@mcollina I forgot to include |
Uh? Using a thenable there should not be supported. |
I think this is a case of insufficient documentation. |
I have a feeling I missed something when we added thenable support to destroy. I'll need to dig into this and check out what's the problem. |
This was added in 744a284 without documentation. The error is not printed because it is not rethrown by the _destroy function. Moreover, the callback should not be mixed with async/await (nor is needed). |
I think we could maybe emit a warning if function returns a thenable when the function.length has the value for the callback signature. |
Wouldn't it be better to throw after the promise resolves and the callback gets called? |
if you implement _destroy(), you need to rethrow or call the callback with the error passed as an argument. |
Again there's this situation where callback may be called after the promise resolves. Currently calling the callback doesn't do anything because at that point the stream is destroyed already because the promise resolved. One can expect |
The documentation must be updated to better specify all of this. I would recommend to add a warning as well when using a promise with a callback. |
I think this is a good first issue. |
Update _destroy to only call onDestroy in case of errors, waiting for the user implementation to call onDestroy on the success path of async functions as well. Fixes: nodejs#40377
Update _destroy to only call onDestroy in case of errors, waiting for the user implementation to call onDestroy on the success path of async functions as well. Fixes: nodejs#40377
Version
v16.10.0
Platform
Linux solus 5.14.7-198.current #1 SMP PREEMPT Wed Sep 22 16:02:46 UTC 2021 x86_64 GNU/Linux
Subsystem
stream
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
What do you see instead?
Additional information
Some undocumented behavior here:
node/lib/internal/streams/destroy.js
Lines 101 to 118 in aff2a0a
The text was updated successfully, but these errors were encountered: