mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 05:36:29 +00:00
Avoid exception when handling closed WebSocket connection (#5630)
When delivering multiple messages to Core, and the first fails with a connection error, the second message will also fail with the same error. But at this point the connection is already clsoed, which leads to an exception in the exception handler. Avoid this compunding error by checking if the connection is still exists before trying to close. Fixes: #5629
This commit is contained in:
parent
2cb2a48184
commit
9b2dbd634d
@ -266,7 +266,8 @@ class HomeAssistantWebSocket(CoreSysAttributes):
|
||||
try:
|
||||
await self._client.async_send_command(message)
|
||||
except HomeAssistantWSConnectionError:
|
||||
await self._client.close()
|
||||
if self._client:
|
||||
await self._client.close()
|
||||
self._client = None
|
||||
|
||||
async def async_send_command(self, message: dict[str, Any]) -> dict[str, Any]:
|
||||
@ -277,7 +278,8 @@ class HomeAssistantWebSocket(CoreSysAttributes):
|
||||
try:
|
||||
return await self._client.async_send_command(message)
|
||||
except HomeAssistantWSConnectionError:
|
||||
await self._client.close()
|
||||
if self._client:
|
||||
await self._client.close()
|
||||
self._client = None
|
||||
raise
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user