-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
requests::Response::content hangs forever for Socket::read #16091
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
Thanks for the report. To properly investigate this we would need instructions on how to reproduce the issue. Eg how to set up the server, and what code to run on the client (what HTTP request). You could also possibly use wireshark to trace the network traffic between the server and client and that may help debug the issue. Do you see the socket read hanging if the client is an ESP32 board? Can you try using normal Python to run the client code? |
I only experience this issue when requesting the current Ahoy-DTU running on an ESP32. The request is made from ESP32 or ESP8266 running the latest Micropython. When I interrupt the execution it gives me the stack trace pointing to read():
The request is the following but all REST calls on ahoy-dtu behave the same: via:
The issue does not appear when run on Python. |
I was able to reproduce the problem, using the following steps:
The issue is in the Ahoy-DTU web server code: it's responding with a HTTP 1.0 header but not following the HTTP 1.0 specification. In particular it's sending The possible fixes are:
|
Great - thank you for your investigations! |
Port, board and/or hardware
ESP32/ESP8266/Unix
MicroPython version
MicroPython v1.23.0 on 2024-06-02; ESP module with ESP8266
Reproduction
I experienced the issue with an ESP running micropython wanting to access an AhoyDTU via simple HTTP GET. After updating the AhoyDTU (latest (ahoy_v0.8.140) https://fw.ahoydtu.de/fw/release%2Fahoy_v0.8.140/) the call got stuck and the ESP hangs there forever.
As other HTTP clients do not have any issues requesting the server, I see the issue independent from AhoyDTU and request micropython to be more robust here.
Expected behaviour
No response
Observed behaviour
Depending of the server's message requests::Response::content hangs as the internal Socket::read() blocks and hangs forever. As the documentation for Socket::read() says it waits until EOF is recognized I assume this is the issue here.
Additional Information
In case a Content-Length is being transmitted Response::content should only read the amount of bytes as denoted by Content-Length. I case the message is being streamed, read() shall be used to read until EOF is recognized.
I was able to fix this locally by doing the following:
Try to read Content-Length from HTTP headers and conditionally set it at the response object. In case Response::content is requested and the socket is used to read the payload, check if Content-Length is available and conditionally only read the denoted amount of bytes via Socket::read(int) which does not wait for EOF. In case no Content-Length is available, do the Socket::read() as before.
fix-requests-hangs-on-read.zip
Code of Conduct
Yes, I agree
The text was updated successfully, but these errors were encountered: