Skip to content

Commit 303adf8

Browse files
committed
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.
1 parent 8e0b86a commit 303adf8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

adafruit_httpserver/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def poll(self) -> str:
360360
if self.stopped:
361361
raise ServerStoppedError
362362

363+
conn = None
363364
try:
364365
conn, client_address = self._sock.accept()
365366
conn.settimeout(self._timeout)
@@ -405,7 +406,8 @@ def poll(self) -> str:
405406
if self.debug:
406407
_debug_exception_in_handler(error)
407408

408-
conn.close()
409+
if conn is not None:
410+
conn.close()
409411
raise error # Raise the exception again to be handled by the user.
410412

411413
def require_authentication(self, auths: List[Union[Basic, Token, Bearer]]) -> None:

0 commit comments

Comments
 (0)