fix(observe): re-sync to poll mode on reconnect, harden notified-set race
A poll-failure-triggered reconnect while in observe mode left OBSERVE silently dead: the new session had zero subscriptions, mode stayed 'observe' so the hot/warm sub-poll fallback stayed disabled, and the ObserveRefreshTask kept retrying against the closed session instead of the live one. Downgrading to poll mode on reconnect hands recovery to the existing poll-mode retry path, which re-subscribes on the new session. Also snapshot ObserveManager._notified before intersecting it against the subscribed set, closing a rare set-mutated-during-iteration race between the DTLS reader thread (on_notification) and the executor thread computing the grace-period success fraction.
This commit is contained in:
1 parent
8042fe715b
commit
7024b170fe
3 files changed
+69
-2
No files matched your search
@@ -345,6 +345,20 @@ class LocalThingsCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
_LOGGER.debug("Full error:", exc_info=e2)
|
||||
return flatten(self.bound, snapshot)
|
||||
raise UpdateFailed(f"poll failed after reconnect: {e2}") from e2
|
||||
else:
|
||||
# The reconnect gave us a brand-new session with zero
|
||||
# OBSERVE registrations. If we were in observe mode,
|
||||
# that state is now stale — the refresh task is still
|
||||
# pinned to the old (closed) session and nothing will
|
||||
# ever re-subscribe on the new one. Tear it down now so
|
||||
# the existing poll-mode retry path (_maybe_retry_observe_mode)
|
||||
# re-subscribes on the live session on its next cycle.
|
||||
if self._observe.mode == MODE_OBSERVE:
|
||||
_LOGGER.debug(
|
||||
"reconnect while in observe mode; downgrading to "
|
||||
"poll so recovery re-subscribes on the new session"
|
||||
)
|
||||
self._observe.downgrade_to_poll()
|
||||
|
||||
source = 'sweep' if self._discovered else 'poll'
|
||||
if self._observe.mode == MODE_OBSERVE and self._observe.check_sweep_for_misses(resources):
|
||||
|
||||
@@ -111,7 +111,7 @@ class ObserveManager:
|
||||
|
||||
time.sleep(grace_period_s)
|
||||
|
||||
fraction = len(self._notified & subscribed) / len(subscribed)
|
||||
fraction = len(set(self._notified) & subscribed) / len(subscribed)
|
||||
if fraction >= success_fraction:
|
||||
self.subscribed_hrefs = subscribed
|
||||
self._set_mode(MODE_OBSERVE)
|
||||
|
||||
Reference in new issue
Block a user