-
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
streams: calling end while ending will never invoke callback? #28667
Comments
@mcollina ping |
http/1 has the same "problem" |
The callback is added as a listener of the |
There is no memory leak because the callback is used only on the first |
I think adding an error to the callback if the stream has already emitted end could be accepted. We need to verify this would not break CITGM. There should be enough state on Readable around to easily add a check. |
You mean writable.on('finish', () => {
writable.end(() => {
// Called with an error.
});
});
writable.end(() => {
// Called when `'finish'` is emitted.
});
writable.end(() => {
// Called when `'finish'` is emitted?
});
writable.end(() => {
// Called when `'finish'` is emitted?
});
// ... |
https://github.com/nodejs/node/blob/master/lib/_stream_writable.js#L592 if |
Yes. |
maybe? writable.on('finish', () => {
writable.end((err) => {
// error
});
});
writable.end((err) => {
// ok
});
writable.end((err) => {
// error
});
writable.end((err) => {
// error
}); I'm unsure... |
@ronag I think that suggestion is just fine 👍 The only real alternative I could see is also calling the callbacks for the subsequent |
Invoke callback with ERR_STREAM_ALREADY_FINISHED error if `end()` is called on a finished stream. PR-URL: #28687 Refs: #28667 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This has been sorted |
Calling
end()
twice with callback will cause the second callback to never be invoked:e.g. the following will fail.
I'm not sure what the behavior should be here. Maybe calling the callback with an error? Either way, not calling the callback at all seems to me like it will cause problems and memory leaks.
The text was updated successfully, but these errors were encountered: