Description
This does seem to be a distinct issue. The typical simpletest URLs all have a content-length
header, but with a URL using {'transfer-encoding': 'chunked'}
header in the legacy API, Requests will get Failed to send {num} bytes (sent 0)
every other time (alternating), and on the 21st loop will get No sockets available
thereafter.
CONFIG_LWIP_MAX_SOCKETS=10
in https://github.com/adafruit/nina-fw/blob/master/sdkconfig), and sockets become available again with esp.reset()
, so those clues point to the socket not getting closed.
The odd loops work fine and return quickly. The even loops seem to use the full timeout
before returning with the Failed to send
... exception. I haven't found why the code does this alternating pattern, seems to indicate something not being (de)init, and may just be the socket not getting closed on alternate iterations because {mystery} reasons.
Tested on:
Adafruit Feather M4 Express with samd51j19
CircuitPython 5.3.1 on 2020-07-13 and 6.0.0-alpha.3 on 2020-08-28
CircuitPython Library Bundle 6.x-mpy-20200918 and #33
Test code snippet:
loop = 1
while True:
print("Fetching text...") # from %s" % CHUNKED_URL)
try:
print(loop, end=" ")
response = requests.get(CHUNKED_URL, timeout=5)
# print(response.content)
print(response.status_code, end=" ")
print(response.reason, end=" ")
print(response.headers)
print(response.text)
response.close()
except (AttributeError) as e:
print("AttributeError:", e)
except (RuntimeError) as e:
print("RuntimeError:", e)
if "No sockets available" in repr(e):
continue
# esp.reset()
# esp.connect_AP(secrets["ssid"], secrets["password"])
time.sleep(1)
print()
loop += 1
Also, if response.text
is not accessed, the second loop will result in:
Fetching text...
2 Traceback (most recent call last):
File "code.py", line 108, in <module>
File "code.py", line 98, in <module>
File "/lib/adafruit_requests.py", line 605, in get
File "/lib/adafruit_requests.py", line 475, in request
File "/lib/adafruit_requests.py", line 252, in close
TypeError: unsupported types for __gt__: 'NoneType', 'int'
Seems _remaining
doesn't get set after its initialization to None
in that execution path.