Fix failed disconnect requests not being logged (#511)

This commit is contained in:
J. Nick Koston 2023-07-27 08:25:46 -05:00 committed by GitHub
parent 3054eb5113
commit 762d00faff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -799,7 +799,12 @@ class APIConnection:
# Try to wait for the handshake to finish so we can send
# a disconnect request. If it doesn't finish in time
# we will just close the socket.
await asyncio.wait([self._connect_task], timeout=5.0)
_, pending = await asyncio.wait([self._connect_task], timeout=5.0)
if pending:
_LOGGER.debug(
"%s: Connect task didn't finish before disconnect",
self.log_name,
)
self._expected_disconnect = True
if self._is_socket_open and self._frame_helper:
@ -811,8 +816,10 @@ class APIConnection:
await self.send_message_await_response(
DisconnectRequest(), DisconnectResponse
)
except APIConnectionError:
pass
except APIConnectionError as err:
_LOGGER.error(
"%s: Failed to send disconnect request: %s", self.log_name, err
)
self._set_connection_state(ConnectionState.CLOSED)
self._cleanup()