Skip to content

Commit

Permalink
Add temporary guard for infinite loop in resub logic (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Nov 4, 2023
1 parent 32b654c commit d38e5b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions matter_server/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MatterNodeData:
attribute_subscriptions: set[tuple[int | str, int | str, int | str]] = field(
default_factory=set
)
last_subscription_attempt: float = 0


@dataclass
Expand Down
21 changes: 21 additions & 0 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from functools import partial
import logging
import random
import time
from typing import TYPE_CHECKING, Any, Callable, Iterable, Type, TypeVar, cast

from chip.ChipDeviceCtrl import CommissionableNode
Expand Down Expand Up @@ -731,6 +732,26 @@ def resubscription_attempted(
nextResubscribeIntervalMsec: int,
) -> None:
# pylint: disable=unused-argument, invalid-name
cur_timestamp = time.time()
if (
nextResubscribeIntervalMsec > 30000
and (cur_timestamp - node.last_subscription_attempt) < 2
):
# Guard for a (possible) bug in the sdk where the resubscription gets into
# an endloop loop where this callback is hit multiple times per second.
node_logger.error(
"Infinite loop detected in resubscription, "
"start manual resubscription logic."
)
# cancel subscription and add this node to our node polling job
sub.Shutdown()
self._subscriptions.pop(node_id)
assert self.server.loop
self.server.loop.create_task(
self._check_interview_and_subscription(node_id, MAX_POLL_INTERVAL)
)
return
node.last_subscription_attempt = cur_timestamp
node_logger.info(
"Previous subscription failed with Error: %s, re-subscribing in %s ms...",
terminationError,
Expand Down

0 comments on commit d38e5b3

Please sign in to comment.