adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

fix out of sockets issue #74

Closed jfurcean closed 3 years ago

jfurcean commented 3 years ago

Fixes problem when there are free sockets but are not closed when needed. See #73

brentru commented 3 years ago

@jfurcean Could you clarify why you are except'ing the RuntimeError: Out of sockets"? Is this being thrown erroneously by CircuitPython?

Neradoc commented 3 years ago

The assumption is that it is being thrown correctly, so it triggers a retry on the loop, which in turn causes a call to self._free_sockets() which would close the "free" sockets. Requests otherwise doesn't automatically close the sockets it uses, it keeps them, only marking them as "free" when no longer in use, and reuses them when you access the same host/port, leading to inevitably running out of sockets.

In 6.2 beta 1 the same code would cause a MemoryError on sock.connect() in that same loop which in turn would also cause the freeing of sockets. That change to a more specific error message is a consequence of the "Separate SSLSocket from Socket" PR.

brentru commented 3 years ago

In 6.2 beta 1 the same code would cause a MemoryError on sock.connect() in that same loop which in turn would also cause the freeing of sockets. That change to a more specific error message is a consequence of the "Separate SSLSocket from Socket" PR.

I see, thank you for the clarification! I'm going to implement a similar patch within MiniMQTT.