From cee7f22fa384d49ffc6b3f98c455bdba259c77b1 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 25 Oct 2022 09:50:00 -0500 Subject: [PATCH] Explicitly set accepted socket to blocking The Python documentation states that otherwise, the blocking status of the newly accepted socket is implementation-defined: > if the listening socket is in non-blocking mode, whether the socket > returned by accept() is in blocking or non-blocking mode is operating > system-dependent. If you want to ensure cross-platform behaviour, > it is recommended you manually override this setting. When the connected socket is non-blocking (as it is on picow), the http library works erratically, depending whether the request has already arrived by the time recvfrom_into call occurs. Closes: adafruit/circuitpython#7086 --- adafruit_httpserver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_httpserver.py b/adafruit_httpserver.py index a3fc764..a1b522d 100644 --- a/adafruit_httpserver.py +++ b/adafruit_httpserver.py @@ -342,6 +342,7 @@ def poll(self): try: conn, _ = self._sock.accept() with conn: + conn.setblocking(True) length, _ = conn.recvfrom_into(self._buffer) request = _HTTPRequest(raw_request=self._buffer[:length])