mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 11:06:32 +00:00
Fix issue with concurrent reads (#2610)
* Fix issue with concurrent reads * Use lock * acquire/release * handle ConnectionError * No there was not mulitple issues, it's the same code just different syle.....Which is stated on the same page as that image...
This commit is contained in:
parent
8630adc54a
commit
cb5932cb8b
@ -612,7 +612,7 @@ class Addon(AddonModel):
|
||||
try:
|
||||
await self.instance.run()
|
||||
except DockerRequestError as err:
|
||||
self.state = AddonState.STOPPED
|
||||
self.state = AddonState.ERROR
|
||||
raise AddonsError() from err
|
||||
except DockerError as err:
|
||||
self.state = AddonState.ERROR
|
||||
@ -625,6 +625,7 @@ class Addon(AddonModel):
|
||||
try:
|
||||
await self.instance.stop()
|
||||
except DockerRequestError as err:
|
||||
self.state = AddonState.ERROR
|
||||
raise AddonsError() from err
|
||||
except DockerError as err:
|
||||
self.state = AddonState.ERROR
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Home Assistant Websocket API."""
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
@ -24,29 +25,34 @@ class WSClient:
|
||||
self, ha_version: AwesomeVersion, client: aiohttp.ClientWebSocketResponse
|
||||
):
|
||||
"""Initialise the WS client."""
|
||||
self.ha_version = ha_version
|
||||
self.client = client
|
||||
self.message_id = 0
|
||||
self.ha_version: AwesomeVersion = ha_version
|
||||
self.client: aiohttp.ClientWebSocketResponse = client
|
||||
self.message_id: int = 0
|
||||
self._lock: asyncio.Lock = asyncio.Lock()
|
||||
|
||||
async def async_send_command(self, message: Dict[str, Any]):
|
||||
"""Send a websocket command."""
|
||||
self.message_id += 1
|
||||
message["id"] = self.message_id
|
||||
async with self._lock:
|
||||
self.message_id += 1
|
||||
message["id"] = self.message_id
|
||||
|
||||
_LOGGER.debug("Sending: %s", message)
|
||||
try:
|
||||
await self.client.send_json(message)
|
||||
except HomeAssistantWSNotSupported:
|
||||
return
|
||||
_LOGGER.debug("Sending: %s", message)
|
||||
try:
|
||||
await self.client.send_json(message)
|
||||
except ConnectionError:
|
||||
return
|
||||
|
||||
response = await self.client.receive_json()
|
||||
try:
|
||||
response = await self.client.receive_json()
|
||||
except ConnectionError:
|
||||
return
|
||||
|
||||
_LOGGER.debug("Received: %s", response)
|
||||
_LOGGER.debug("Received: %s", response)
|
||||
|
||||
if response["success"]:
|
||||
return response["result"]
|
||||
if response["success"]:
|
||||
return response["result"]
|
||||
|
||||
raise HomeAssistantWSError(response)
|
||||
raise HomeAssistantWSError(response)
|
||||
|
||||
@classmethod
|
||||
async def connect_with_auth(
|
||||
|
Loading…
x
Reference in New Issue
Block a user