-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ESP8266HTTPclient http.getstring() causing delays since version 2.5.1 #6501
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
Comments
One of the changes in the PR you linked is the change of waiting for the number of bytes available (old) to number of bytes expected. So I guess the Fritzbox is giving less than the expected amount of data? (or not fast enough?) |
Thanks for the fast feedback - that could well be the case ... From reading up, it looks like the content lenght header is not used for "chunked transfer encoding" - as the chunks have the lenght in them .... So this might be the root cause of the issue - is there any way that this might be fixable in the library code, as this was working with no issue up to 2.5.0. As content lenght header ist not available for chunked transfers, library should somehow be able to handle that. I´m afraid I do not fully understand the code to really understand the impact of the change from bytes available (old) the bytes expected. |
Chunked transfer will end with a 0-length chunk.
See: developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding |
Well, let's see "you" as the more common interpretation :) |
What would be helpful is a way to reproduce: an MCVE and an URL |
Hi, An URL is a bit harder, as this is from calling up the router internal URL. But anybody having a Fritz box router (which is very popular in Europe at least) should be able to reproduce calling up the URL I´ll dig around to see if I can find another public URL that uses chunked transfer encoding and will try duplicating with that ... |
ESPeasy does serve its web pages (and JSON) as chunked transfer :) |
MCVE yes of course sorry, but I have no URL. Fritz Boxes are essentially on the german market and I can't have one. I tried jigsaw with emulation on host and it does not work, because data are greater than 64K.
Looking for another chunk-encoded source before I try to use a local one. |
So I forged an http response with only one chunk and served it with
"can't reproduce" |
Then please could you try this MCVE with one of your esp as webserver and tell if you observes any timeout ?
|
Hello, thanks folks for helping me with this.
One thing I find strange - but might be a lack of my understanding: The http.getString() is what is actually causing the 5 second delay since version 2.5.1. as you can see here (not sure wha the pm open,type:2 0 means):
Thanks again for your help and hanging in here with me with your valuable time. Regards - MacSass |
Here is the network trace from where the ESP actually requests the URL from the router - it looks a bit different from my previous network trace, where I pulled the URL with Firefox (it was just to see how the router responds) - I hope this did not create more confusion, than it did good: I´m not totally sure if this is still a chunked response at all as I don´t see the respective header. |
From your esp log above, you are not using git master ( timestamps is an option that can be enabled on the arduino serial console window. |
Found the timestamp :-) and updated the debug output. I installed the latest version via boardmanager in arduino ide (2.5.2) now - see updated debug output above - is that OK? Or do I need to manually install from git? Thanks - MacSass |
I could not reproduce with latest git, so it is better if you can give a try with it. |
@d-a-v : Isn´t arduino boardmanager pulling the latest master version? It shows 2.5.2 now in my debug output (see above) - or should it show something different?
|
Git version installation is on the main page: https://github.com/esp8266/Arduino#quick-links |
From your debug information:
You can tell that your code passes this line. However, it does not reach this line. This is because the router does not send a 'Content-Length' header, so _size == 0. The client can not tell the size of the data it is getting. The server does not send a 'Transfer-Encoding: chunked' header neither, and, as far as I can see, the data is not chunked, so this is correct. If it would be chunked, the client could determine the end of the data because every chunk has a size header. Since the data is not chunked, it can not determine the end of the data stream. The combination of the missing of both headers leads to the failure, because the while loop 2 lines above this line, in combination with the if(len>0) evaluating to 'false', causes the else part to be executed. The else is here and just waits for the timeout. My observations are:
|
AFAICT from w3.org and a quick look at the RFC2616 there, having neither header is not specified behavior, i.e.: either Content-Length must be present, or Transfer-Encoding: chunked must be present. If both are present, Content-Length must be ignored. I don't see mention of neither being present, hence unspecified. |
Hello, I will do some more investigation and in case I come to the conclusion we still have an issue in the code, I´ll do a re-open. Until then I can always go back to 2.5.0 version, which works perfectly for me. Thanks for your time - hope to have some more details and a better undestanding of what is going on soon. Regards - MacSass |
Hello, Thanks - MacSass |
The workaround for this is to set timeout to 1 just before getString. |
@hojnorek this is a long-time-closed issue. |
Basic Infos
Platform
Settings in IDE
Problem Description
I have a fairly simple sketch that uses ESP8266HTTPClient to pull a XML from my AVM Fritz Box router. It downloads a challenge file that is needed in ongoing process to calculate a response and login to the router ...
Since core version 2.5.1 this single HTTP request takes 5000ms longer than with previous versions. In fact the http.getString() is what causes the 5000ms delay. Same code compiled with up to version 2.5.0 the same request only takes about 300ms.
This issue does not apply to all HTTP requests, pulling the same XML from my website, the additional 5000ms time delay is not seen.
Comparing version I found there was a change in honoring the http.timout delay and I suspect that the changes made cause the http.getstring() to wait for the timeout instead of coming back directly after the file has been read.
Honor timeout in HTTPClient #6056
Unfortunately I´m not savy enough to identify the exact issue. Also, as it does not apply to all http requests, I suspect it might only happen if the webserver does not send a standard C string with correct terminating characters.
As said - that is / was no issue up to version 2.5.0
I also tried to reduce the http.timout() to e.g. 1000ms, which reduced the overall time, but still http.getstring always has to wait for the timeout, which was not the case prior to version 2.5.1.
Sample Sketch
If you require any more information, please let me know.
The text was updated successfully, but these errors were encountered: