circuitpython: raspberrypi 8.0.0 socket exceptions when web workflow is enabled
CircuitPython version
Adafruit CircuitPython 8.0.0-beta.5 on 2022-12-08; Raspberry Pi Pico W with rp2040
Code/REPL
import time
import traceback
import wifi
import socketpool
import ssl
import adafruit_requests
from secrets import secrets
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
print("Connecting...")
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("My IP address is", wifi.radio.ipv4_address)
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
while True:
try:
print("Fetching text from", TEXT_URL)
response = requests.get(TEXT_URL)
print("-" * 40)
print(response.text)
print("-" * 40)
except Exception as e:
traceback.print_exception(e, e, e.__traceback__)
time.sleep(5)
Behavior
The above code, slightly modified boilerplate internet connect code, does not work on raspberrypi
8.0.0-beta.5 when web workflow is enabled (wifi credentials in .env
file).
Consistently gets exception:
Traceback (most recent call last):
File "code.py", line 139, in get_http
File "adafruit_requests.py", line 718, in post
File "adafruit_requests.py", line 679, in request
OutOfRetries: Repeated socket failures
It seems that the timeout in requests is kicking in within the library. No data is received. Occasionally ETIMEDOUT
.
Underlying exceptions to the OutOfRetries
occur (discovered through some print-debugging in adafruit_requests
) if a manual timeout is supplied. Exceptions are initially OSError: [Errno 116] ETIMEDOUT
in recv_into
, waiting for the H
of HTTP
to kick off the receive. Then OSError: 32
in _send
takes over on later requests. But again, sometimes there is no error, just no data received.
I suspect some low-level socket shenanigans. There should be 8 sockets available, web workflow uses at least one for the TCP listen
, probably something for mDNS, and more with client(s) accessing web workflow features?
Interestingly If requests alternate between two URLs, after several failures for both, the second will succeed once. Rinse, repeat.
No issue with the above code on 8.0.0-beta.4, or on 8.0.0-beta.5 with web workflow disabled (no .env
file).
Description
No response
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23 (16 by maintainers)
Commits related to this issue
- Merge pull request #7589 from gneverov/issue_7333 Increase number of LWIP timers for MDNS (fixes #7333) — committed to adafruit/circuitpython by tannewt a year ago
Tested. Fixed by #7589. Thanks, @gneverov!
hyde00001 confirmed on Discord just now that a delay at the start of the code works as above, once the board is then reset.