OctoPrintAPI icon indicating copy to clipboard operation
OctoPrintAPI copied to clipboard

Infinite loop (or almost) with OctoprintApi::sendRequestToOctoprint()

Open fmatray opened this issue 5 years ago • 4 comments

Hello, The the method OctoprintApi::sendRequestToOctoprint() seems, with some occasion, loop for ever or almost.

One of the occasion is with this answer (octoprint is down and Nginx is responding) :

HTTP/1.0 502 Bad Gateway
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>

The code is waiting for a "Content-Length" that never happen.

What do you think about using ArduinoHttpClient instead of a custom code ? https://github.com/arduino-libraries/ArduinoHttpClient

fmatray avatar Jun 01 '20 23:06 fmatray

I could take a look at the code to see if we can catch this event. The custom code was to allow for any network client (esp8266, esp32, ethernet etc) to connect without dependencies.

We could utilise the return code (502) if not 200, and break out the loop? Will take a look on a break - but good spot - you're really pushing the library to some good edge cases! :)

steve

chunkysteveo avatar Jun 02 '20 07:06 chunkysteveo

I’m not sure this is the only event with such problem . And it’s not easy to test all cases: direct request to octoprint, Nginx, Apache, Haproxy, etc. It could depend on the configuration.

Custom codes for generic function, like http request, tend to be more buggy, as they are not tested as well as a standard library. That’s why, high level library focused should rely on mid level ones.

A way to keep the compatibility with Arduino and ESPxxxx is to use directives:

#if defined(ARDUINO)
// Arduino specific code 
#elif defined(ESP8266)
// ESP8266 specific code
#else
#Error “Platerform not supported”
#endif

I’m haven’t the exact code, it’s just for the idea. I have no more ESPxxxx board at home, I can only test with an MKR 1010.

fmatray avatar Jun 02 '20 08:06 fmatray

After 4 days of test, I have no more infinite loops.

The problem was with empty responses like 502 and, also, with the Wifi driver.

On the MKR 1010, perhaps with other boards, if WifiClient::available() is called too often, the driver receives errors from the ESP and can't deal with it. That's why there is delay(100) while waiting.

fmatray avatar Jun 06 '20 19:06 fmatray

you've been busy again! Let me check out the updates and have a play with my ESP boards.

Steve

chunkysteveo avatar Jun 07 '20 13:06 chunkysteveo