From 303adf874c83913d777374b0001679ef53cdc05b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 16 Feb 2024 09:58:33 -0600 Subject: [PATCH] Preserve the real error if accept failed. Otherwise, the exception would be about the variable 'conn' never being assigned a value. This scenario came up when there was an internal bug in circuitpython sockets that made accept fail; however, it might be the case that accept can "normally" fail, e.g., if all sockets are exhausted. --- adafruit_httpserver/server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_httpserver/server.py b/adafruit_httpserver/server.py index 183c646..87d16fe 100644 --- a/adafruit_httpserver/server.py +++ b/adafruit_httpserver/server.py @@ -360,6 +360,7 @@ def poll(self) -> str: if self.stopped: raise ServerStoppedError + conn = None try: conn, client_address = self._sock.accept() conn.settimeout(self._timeout) @@ -405,7 +406,8 @@ def poll(self) -> str: if self.debug: _debug_exception_in_handler(error) - conn.close() + if conn is not None: + conn.close() raise error # Raise the exception again to be handled by the user. def require_authentication(self, auths: List[Union[Basic, Token, Bearer]]) -> None: