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
Fix for erroneous MG_EV_HTTP_CHUNK #1656
Conversation
Do not send MG_EV_HTTP_CHUNK if chunk len would be zero and response is not yet fully received. This can occur in circumstances where the first socket read contains only the header (no data). In this case, the calculated chunk length is zero.
This issue can be observed using the http-streaming-client example with a local URL to a file served with pythons http server. e.g. (client):
server:
With the fix in place, it will instead print the file (word list). I think http.server (and probably others) send only the header in the first packet. Depending on timing, this results in hitting this bug and the client will not print the resource. This happens to me more often than not, but not always. Client logic is (correctly) to consider the response complete on receiving a chunk of zero length. |
Can you please run Wireshark and check what is actually going on ? Please post the capture file (preferably with no other traffic) |
I think @david-collett observes a situation when a server sends headers, then pauses, then sends a body. Mongoose client receives headers, then tries to send a HTTP chunk - and since no content is sent by a server YET, it report a zero chunk which is a marker for the end of data. That situation should definitely be covered by the unit test. |
Yeap, that can be clearly seen in the capture. The server pauses after sending the whole headers and starts sending the body ~100us later, but the client has already disconnected. |
Check PR #1658 |
Yeah, that test reproduces the issue in the eh5 handler. The patch in this PR passes the test. |
I've refactored MG_EV_HTTP_CHUNK functionality, to make it predictable and stable. |
@david-collett could you pull the change and test on your code please? |
I believe your changes may introduce a problem, but I don't have time to fully debug it now, instead I will describe what I am seeing. I have test code that does a HTTP get, followed by another HTTP get on the same connection (pipelining). The resource requested is very small (8 bytes). In the old code I got a MSG callback for each request with the 8 bytes of the resource. With the new code, I get a CHUNK callback of 8 bytes, followed by a CHUNK callback if 0 bytes for the first request (no MSG callbacks as I am deleting chunks), and the data is good. So far so good. But for the second response, I seem to get the two CHUNK callbacks(8, 0), followed by a MSG callback with 16 bytes containing data of HTTP. The CHUNK callback has 200 OK as the bytes and the MSG callback has HTTP 1.1 etc. mongoose subsequently logs http parsing errors. So I think the buffers / state are not properly reset between the two responses? |
I have replied in the original PR about a possible issue with your changes.
…On Fri, 5 Aug 2022 at 02:11, Sergey Lyubka ***@***.***> wrote:
@david-collett <https://github.com/david-collett> could you pull the
change and test on your code please?
—
Reply to this email directly, view it on GitHub
<#1656 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJPAEO36AUUJA6ZQLBAB3TVXPTS5ANCNFSM55NUZIGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@david-collett I confirm the issue with the pipelined requests. Going to add a unit test and a fix for it. |
@david-collett please pull the latest, and test again. |
Unfortunately I get exactly the same result with this patch. |
Ok, I found the problem. The following fixes it:
|
This case can be tested as follows:
|
@david-collett thank you for taking your time to test, dig and fix! |
no worries!
…On Sat, 6 Aug 2022 at 18:02, Sergey Lyubka ***@***.***> wrote:
@david-collett <https://github.com/david-collett> thank you for taking
your time to test, dig and fix!
Pushed 740b609
<740b609>
—
Reply to this email directly, view it on GitHub
<#1656 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJPAENNXMSG5RWBYFHUYLTVXYLZPANCNFSM55NUZIGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@david-collett does the the latest HEAD work as expected? |
Yep, its working for me, thanks. |
Do not send MG_EV_HTTP_CHUNK if chunk len would be zero and
response is not yet fully received.
This can occur in circumstances where the first socket read
contains only the header (no data). In this case, the calculated
chunk length is zero.