You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incomplete control code while parsing chunked stream #67
I'm using wyrihaximus/react-guzzle-psr7 to send async requests with Guzzle HTTP, however, the server I am requesting has recently started using chunked HTTP requests. I saw that chunked requests was recently introduced into the HTTP client by the creator of the package I am using however I am still getting the error Stream ended with incomplete control code. Is this a client side problem?
Have you checked the server is actually sending a valid chunked encoded stream? Can you post a public URL to test this?
The server might close the connection prematurely which would result in this error. Perhaps we may want to look into providing a non-strict parser (Be strict in what you send, but generous in what you receive).
Hey @uniquoooo the Stream ended with incomplete control code exception is thrown when the request ends in an unclean way. Do you have a easy way to reproduce this issue?
There isn't a public URL that I can post as it requires authorization, however, I can capture the response. Would it be fine if I capture it with curl -iv --raw?
@uniquoooo any change you can supply a pcap of the communication between your code and that server for a request that fails? Just put your gist into DecodeChunkedStreamTest as a data set, and it passed decoding the message.
If you don't want to share the pcap publicly (which I would discourage tbh) feel free to send it to the email address on my profile.
@uniquoooo Wireshark has a Save as option that just saves the entire capure. I can open the pcapng (or just pcap) file on my machine and go through the request.
Managed to reproduce the issue with help from @uniquoooo, tracking down the cause of it and will submit a PR with a fix once I've came up with a solution.
So the chunked decoding parser is fine, the flaw turns out to be in the moment the headers are parsed and there is a bit of body coming with it from the stream. That bit of body was emitted from the response object while it should have been emitted from the stream. #68 is up to fix that.
@brad-jones could you verify for me that the hot fix I just created works for you? You can test that by swapping vendor/src/react/http-client/src/ChunkedStreamDecoder.php out with this one ChunkedStreamDecoder.php in the mean time I'll write up tests as well for it and create a PR.
It's now causing some requests to hang the whole React loop indefinitely. Not sure if it's the hotfix.
It isn't, the hotfix applied to a specific situation where there is some data left to process. It should never let the loop run indefinitely on it's own.
Activity
clue commentedon Oct 19, 2016
We'll have to figure this out :-)
Have you checked the server is actually sending a valid chunked encoded stream? Can you post a public URL to test this?
The server might close the connection prematurely which would result in this error. Perhaps we may want to look into providing a non-strict parser (Be strict in what you send, but generous in what you receive).
WyriHaximus commentedon Oct 19, 2016
Hey @uniquoooo the
Stream ended with incomplete control codeexception is thrown when the request ends in an unclean way. Do you have a easy way to reproduce this issue?davidcole1340 commentedon Oct 19, 2016
Hi guys,
There isn't a public URL that I can post as it requires authorization, however, I can capture the response. Would it be fine if I capture it with
curl -iv --raw?Thanks
clue commentedon Oct 19, 2016
Might be worth a try 👍 Otherwise a pcap (Wireshark etc.) may also help.
davidcole1340 commentedon Oct 19, 2016
I've uploaded it to GitHub gist here: https://gist.github.com/uniquoooo/c6c05261dbd67dd5f7c3ab5563927a14
WyriHaximus commentedon Oct 22, 2016
@uniquoooo cheers, running tests with it ATM
WyriHaximus commentedon Oct 22, 2016
@uniquoooo any change you can supply a pcap of the communication between your code and that server for a request that fails? Just put your gist into
DecodeChunkedStreamTestas a data set, and it passed decoding the message.If you don't want to share the pcap publicly (which I would discourage tbh) feel free to send it to the email address on my profile.
davidcole1340 commentedon Oct 24, 2016
@WyriHaximus I've captured the request but I'm not sure how to export it, could you help?
WyriHaximus commentedon Oct 24, 2016
@uniquoooo Wireshark has a
Save asoption that just saves the entire capure. I can open the pcapng (or just pcap) file on my machine and go through the request.davidcole1340 commentedon Oct 26, 2016
@WyriHaximus I've sent you an email with the file.
WyriHaximus commentedon Oct 27, 2016
Managed to reproduce the issue with help from @uniquoooo, tracking down the cause of it and will submit a PR with a fix once I've came up with a solution.
Fix reactphp#67 caused by the little bit of body coming with the head…
WyriHaximus commentedon Oct 28, 2016
So the chunked decoding parser is fine, the flaw turns out to be in the moment the headers are parsed and there is a bit of body coming with it from the stream. That bit of body was emitted from the response object while it should have been emitted from the stream. #68 is up to fix that.
Ensure the first bit of body directly after the headers is emitted in…
4 remaining items
brad-jones commentedon Nov 11, 2016
Here are 3 files, captured each time fread was hit before the
Stream ended with incomplete control codeexception is thrown.I have removed / swapped out the sensitive stuff (most of which is just the body of a SOAP request).
react-http-client-issue.1478816829.3675.txt
react-http-client-issue.1478816829.3692.txt
react-http-client-issue.1478816829.3693.txt
WyriHaximus commentedon Nov 20, 2016
@brad-jones thanks, currently debugging 👍
WyriHaximus commentedon Nov 20, 2016
@brad-jones could you verify for me that the hot fix I just created works for you? You can test that by swapping
vendor/src/react/http-client/src/ChunkedStreamDecoder.phpout with this oneChunkedStreamDecoder.phpin the mean time I'll write up tests as well for it and create a PR.Akhawais commentedon Nov 20, 2016
Using WyriHaximus/react-guzzle-psr7:
Async works as expected. However synchronous responses almost always fail.
Sending a sync to Stream Labs API (Which uses chunked transfer encoding) fails with
Connection closed before receiving response.@WyriHaximus Your hotfix has successfuly fixed the issue for me. Thanks for all your continued support!
Akhawais commentedon Nov 20, 2016
It's now causing some requests to hang the whole React loop indefinitely. Not sure if it's the hotfix.
WyriHaximus commentedon Nov 20, 2016
It isn't, the hotfix applied to a specific situation where there is some data left to process. It should never let the loop run indefinitely on it's own.
Akhawais commentedon Nov 20, 2016
Thanks for clearing that up! Posted an issue in your handler repo but pretty sure it belongs here if it uses
http-client.WyriHaximus commentedon Nov 20, 2016
No problem, locally trying to figure out what exactly went wrong. In my cause I was hitting the Blizzard API which sometimes causes the error
WyriHaximus commentedon Nov 22, 2016
@brad-jones @Akhawais If you have time could you test this hotfix with me? https://gist.github.com/WyriHaximus/b6891672a4aaa78830076004b2c7839a It seems to be running fine on my end right now but would appreciate your help testing it
brad-jones commentedon Nov 22, 2016
Yeah its been on my todo list. Ill try and get to it today.
WyriHaximus commentedon Nov 22, 2016
Awesome, let me know how it performs for you 👍
Akhawais commentedon Nov 23, 2016
@WyriHaximus Seems to work fine. Can do more (and longer) tests when I'm home and will report back.
WyriHaximus commentedon Nov 23, 2016
@Akhawais awesome, glad to hear that, I'll get the PR up tonight.