Skip to content

Commit 21ea899

Browse files
committed
Make sure that only one updates is running at a time
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.
1 parent 99e627e commit 21ea899

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

matter_server/server/device_controller.py

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
NodeNotReady,
4343
NodeNotResolving,
4444
UpdateCheckError,
45+
UpdateError,
4546
)
4647
from ..common.helpers.api import api_command
4748
from ..common.helpers.json import JSON_DECODE_EXCEPTIONS, json_loads
@@ -140,6 +141,7 @@ def __init__(
140141
self._wifi_credentials_set: bool = False
141142
self._thread_credentials_set: bool = False
142143
self._nodes_in_setup: set[int] = set()
144+
self._nodes_in_ota: set[int] = set()
143145
self._node_last_seen: dict[int, float] = {}
144146
self._nodes: dict[int, MatterNodeData] = {}
145147
self._last_known_ip_addresses: dict[int, list[str]] = {}
@@ -934,6 +936,13 @@ async def update_node(
934936
)
935937

936938
try:
939+
if node_id in self._nodes_in_ota:
940+
raise UpdateError(
941+
f"Node {node_id} is already in the process of updating."
942+
)
943+
944+
self._nodes_in_ota.add(node_id)
945+
937946
# Make sure any previous instances get stopped
938947
node_logger.info("Starting update using OTA Provider.")
939948
await ota_provider.start_update(
@@ -944,6 +953,7 @@ async def update_node(
944953
self._attribute_update_callbacks[node_id].remove(
945954
ota_provider.check_update_state
946955
)
956+
self._nodes_in_ota.remove(node_id)
947957

948958
return update
949959

0 commit comments

Comments
 (0)