This commit is contained in:
J. Nick Koston 2023-11-27 18:13:29 -06:00
parent 01252e0b2c
commit f76985359a
No known key found for this signature in database
3 changed files with 16 additions and 3 deletions

View File

@ -129,3 +129,5 @@ cdef class APIConnection:
cpdef _handle_ping_request_internal(self, object msg)
cpdef _handle_get_time_request_internal(self, object msg)
cdef _set_fatal_exception_if_unset(self, Exception err)

View File

@ -788,10 +788,15 @@ class APIConnection:
# Only set the first error since otherwise the original
# error will be lost (ie RequiresEncryptionAPIError) and than
# SocketClosedAPIError will be raised instead
self._fatal_exception = err
self._set_fatal_exception_if_unset(err)
self._cleanup()
def _set_fatal_exception_if_unset(self, err: Exception) -> None:
"""Set the fatal exception if it hasn't been set yet."""
if self._fatal_exception is None:
self._fatal_exception = err
def process_packet(self, msg_type_proto: _int, data: _bytes) -> None:
"""Process an incoming packet."""
debug_enabled = self._debug_enabled
@ -898,8 +903,10 @@ class APIConnection:
[self._finish_connect_task], timeout=DISCONNECT_CONNECT_TIMEOUT
)
if pending:
self._fatal_exception = TimeoutAPIError(
"Timed out waiting to finish connect before disconnecting"
self._set_fatal_exception_if_unset(
TimeoutAPIError(
"Timed out waiting to finish connect before disconnecting"
)
)
if self._debug_enabled:
_LOGGER.debug(

View File

@ -173,6 +173,10 @@ async def test_requires_encryption_propagates(conn: APIConnection):
await asyncio.sleep(0)
await asyncio.sleep(0)
assert isinstance(conn._fatal_exception, RequiresEncryptionAPIError)
conn.force_disconnect()
assert isinstance(conn._fatal_exception, RequiresEncryptionAPIError)
conn.report_fatal_error(Exception("test"))
assert isinstance(conn._fatal_exception, RequiresEncryptionAPIError)
@pytest.mark.asyncio