-
Notifications
You must be signed in to change notification settings - Fork 35
OSError: [Errno 116] ETIMEDOUT from socket.recv_into #209
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
A few questions:
I have many boards (not that one in particular) and have not seen that issue come up. |
Thank you Justin. I use CircuitPython 9.2.6 (2025-03-23) and Adafruit Requests version 4.1.10. I'm having the error when sending a POST request to Dropbox API host and route: It might easily be a server thing, because when I send POST to: |
That really doesn't make sense. For any one post there are a bunch of calls to send, I've never seen a case of them sending too fast. What I would recommend is share code that others can test and adding some debug statements to the |
Hi Justin. I know, I had the same reaction :) I have been trying to debug where before the actual send() I print out the data bytes:
Then things worked fine, and that is how I got to the 'solution' of replacing the print() with a delay... I'll have my code in GitHub repo within a few days, and I'll post here the link. |
Hi, My code is available here: https://github.com/istvanzk/xiaocam_cpy In order to use the Dropbox API implemented in this repo, you need to have a Dropbox account and set up an App in your Dropbox App Console. Then follow the OAuth flow, which can be run on a development machine (not the XIAO board), to obtain the access_token and refresh_token. These tokens need to be inserted in the |
I have now tested the same code on a XIAO ESP32C3 board + CircuitPython 9.2.7 and, I got the same error, with the same 'solution' of adding a small delay just before the socket.send(). |
I have been testing this problem further, to try to understand it better. For now, I get this error only when interacting with the Dropbox API server from CircuitPython (their official Python SDK works fine). However ....
|
Our versions of |
Thank you Dan for the pointers. I was now reading the psf/requests#3353 (comment) |
Yes, you could look those up in |
Thank you Dan. I have now tested setting the options for TCP keep-alive as recommended in the other psf/requests#3353 (comment). It did not solve my ETIMEDOUT issue, so I need to dig further. Perhaps I'll rise the discussions also on the Dropbox forum. Status: Unfortunately, so far, the only solution which works is the delay inserted in the |
The issue is now also reported on the Dropbox forum. Let's see ... |
I'll test your code on some other boards on Monday (was traveling, so couldn't before) |
@istvanzk Do you have a Pico W or similar that could also be used to test this, to see if it's specific to Espressif? And if you have any other Espressif boards that are not ESP32-S3, that would also be interesting. |
I don't have a Pico W. I have a Challenger+ RP2350 WiFi6/BLE5 i.e., with a ESP32-C6 co-processor. I'll try to test this next week. |
We don't have support for WiFi on the Challenger board in CircuitPython. I suggested a Pico W because it uses a very different WiFi co-processor and underlying code, but would still use the adafruit_requests. You could even try |
Thank you @dhalbert . OK. I'm going to modify my test code to run on my dev machine (Python 3.12). Btw, for using WiFi on my Challenger board in another project, I was planning to make use of the circuitpython-esp32at. |
I have now done the test on host/dev machine (Python 3.12) using the original Thank you for all the help @dhalbert and @justmobilize ! When/if I find a solution to my problem I'll post it here, just in case others experience similar issues. |
I'm closing this as it does not seem to be an issue with |
It could be an issue with WiFi on the Espressif chips (maybe something is not-quite-done when something returns0. That's why testing on Pico W would be interesting. Do you have a simple test case you could include here? (I did not read all the posts, sorry if it's somewhere above.) I assume we need a Dropbox API key? |
Hi @dhalbert Yes, to test this, one needs a Dropbox account (even a free one would do) to be able to create an App on their servers. I have my code here: https://github.com/istvanzk/xiaocam_cpy , see also earlier post: #209 (comment) In the meantime, on the Drobox forum I was suggested to try one of these:
import wifi
wifi.radio.mtu = 1400 # Add this before API calls My results:
|
If you set the timeout on the very first request, the socket will have it. You can also create a separate request session: requests = adafruit_requests.Session(pool, ssl_context)
requests.get(...)
requests_2 = adafruit_requests.Session(pool, ssl_context, session_id="other")
requests_2.get(..., timeout=60) |
Hi @justmobilize Now, I think my problem is finally solved :) |
The solution to such problems is to use a separate Session, as explained by @justmobilize in #209 (comment). |
@istvanzk that's awesome. If you update your repo and let me know, I'll test a few other boards to see if the same thing is needed or if it's board specific |
@justmobilize My repo https://github.com/istvanzk/xiaocam_cpy/tree/main is now updated, and I removed all references to the 'fix'. I'll test me too, later, on the other XIAO board I have (C3). |
So on a ESP32S2, setting the timeout to something small like |
The timeout increase for ACK seems very specific to Dropbox, but they said "Dropbox API servers may delay ACK packets on purpose (common cloud optimization)". Since one doesn't see the Dropbox on, say, regular Python on a host computer, should we change the default? I'm confused about what the default should be. See for example https://docs.python.org/3/library/socket.html#notes-on-socket-timeouts, where the default timeout is None, which means the socket is blocking and can apparently wait a long time. |
Yeah, in CPython you need to set it if you don't want it to block forever. But since things are usually threaded, or you are doing one thing at a time, it's not a big deal. I personally don't think blocking in circuitpython makes as much sense. But maybe? |
I have not tried using 0.1 or 0.3 values, but the case which kept failing for me was with 10sec timeout and common session with other requests (to Adafruit IO). I had to, both separate the Dropbox calls to a separate session and also set the timeout to 60sec (as the default in the Dropbox Python API), while for the other calls the timeout is 10sec (probably can be set lower) |
I'm just saying that since the domain is different, you don't need a different session. Connection Manager grabs a new socket for each domain, so as long as all the calls to dropbox send the same timeout value, you just need the one request session |
Unfortunately, my problem is back. I tried today and again I get the same error, even with the last setup which was working 2 days ago :(. It very much looks like a Dropbox server problem to me, either on purpose or a genuine error.... I don't know. Perhaps I'll give up using Dropbox for this purpose and look for another solution.... |
Hi,
When testing POST requests from a XIAO ESP32S3 (Sense) board, I get this exception error:
i.e. the exception is thrown by
I managed to further trace the problem back to the when the request is sent in line 643:
where the actual sending of the bytes seems to fail, possibly due to some HW/SW buffering reasons. Hence the response received is wrong.
My solution was to add a small delay before line 449:
so it becomes:
With this change I do not have anymore the ETIMEDOUT error.
Alternatively, I have also tried to have a delay inserted before/after the
self._send_request(...)
but that did not solve the timeout problem.I did test also the same code on XIAO ESP32C3, with the same result. I don't know if it is a specific problem/solution for XIAO, ESP32, ... board, or a more general one.
The text was updated successfully, but these errors were encountered: