-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
http: Stream#write with an empty buffer does not call callback #22066
Comments
Note: it only hangs on empty buffers, not empty strings. |
I think this has come up before, in some form? It would be a breaking change but probably worth it. /cc @nodejs/http |
I reported the original issue to
output:
|
@amitzur The code that returns early with an empty buffer is specific to HTTP, not to writable streams in general. Your example doesn't use HTTP, so that's why it works. |
ahh, right right. For example:
|
Fixed in 413a7e1. |
It does not explicitly mention that the callback will not be called, however. So this doesn't address my original issue. Also, please note that
so this is a problem as well. |
@mcollina Do I create a new issue? |
@RubenVerborgh I think it does 413a7e1#diff-69e1ac0b5bfc06e74f2c1ab7b062c6afR753 - When I read that, I assume Would you like to send a PR with the text that would be ok for you?
Can you please upload a snippet that show this? The check and the logic is identical, so I don't see how it's possible that the two call will behave differently |
Proposal in #22461. That said, spelling things out explicitly begs the question whether it is a good design decision to have this exception for empty buffers. Basically, every call to |
I thought I had evidence for this in a test suite of a project, but I was mistaken. The behavior is identical indeed, as expected from the code. |
@RubenVerborgh thanks for checking! |
We still want to change the behaviour so that the callback does get called, right? I.e. #22461 is not a full resolution of this issue, right? |
That matches the behavior of streams unfortunately, it’s not just http. There is no guarantee that the write callback is called. |
In that case, we might want to update the documentation at https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback. |
That doc is correct in the letter, but possibly unclear to the reader. The
callback is called when data is flushed, however it’s _not_ called if it’s
not flushed (as an example in case of errors unrelated to the write).
If we can frame it better, would you mind sending a PR our way? Thanks!
Il giorno mer 22 ago 2018 alle 23:22 Ruben Verborgh <
[email protected]> ha scritto:
… There is no guarantee that the write callback is called.
In that case, we might want to update the documentation at
https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#22066 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADL44lNmBkqjiUWu7A3cp2bKVpE9lNMks5uTcuxgaJpZM4Vq_Vs>
.
|
In #22493 (comment), @mcollina confirmed that Can we fix |
Yes. |
Ensure that the callback of `OutgoingMessage.prototype.write()` is called even when writing empty chunks. Fixes: nodejs#22066
Ensure that the callback of `OutgoingMessage.prototype.write()` is called even when writing empty chunks. Fixes: #22066 PR-URL: #27709 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
When writing an empty buffer, Stream#write does not call the callback: https://github.com/nodejs/node/blob/v10.7.0/lib/_http_outgoing.js#L608
Is this intended? If so, this should probably be mentioned explicitly in the documentation.
If not, we might want to fix this.
The text was updated successfully, but these errors were encountered: