Skip to content

Commit

Permalink
Make sure that only one updates is running at a time
Browse files Browse the repository at this point in the history
Running multiple updates on the same node doesn't make sense. This
should be mostly handled by the client/UX. But we do check on server
side for the critical path.
  • Loading branch information
agners committed Jun 12, 2024
1 parent 99e627e commit 21ea899
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
NodeNotReady,
NodeNotResolving,
UpdateCheckError,
UpdateError,
)
from ..common.helpers.api import api_command
from ..common.helpers.json import JSON_DECODE_EXCEPTIONS, json_loads
Expand Down Expand Up @@ -140,6 +141,7 @@ def __init__(
self._wifi_credentials_set: bool = False
self._thread_credentials_set: bool = False
self._nodes_in_setup: set[int] = set()
self._nodes_in_ota: set[int] = set()
self._node_last_seen: dict[int, float] = {}
self._nodes: dict[int, MatterNodeData] = {}
self._last_known_ip_addresses: dict[int, list[str]] = {}
Expand Down Expand Up @@ -934,6 +936,13 @@ async def update_node(
)

try:
if node_id in self._nodes_in_ota:
raise UpdateError(
f"Node {node_id} is already in the process of updating."
)

self._nodes_in_ota.add(node_id)

# Make sure any previous instances get stopped
node_logger.info("Starting update using OTA Provider.")
await ota_provider.start_update(
Expand All @@ -944,6 +953,7 @@ async def update_node(
self._attribute_update_callbacks[node_id].remove(
ota_provider.check_update_state
)
self._nodes_in_ota.remove(node_id)

return update

Expand Down

0 comments on commit 21ea899

Please sign in to comment.