Copy callback list before dispatching updates#44
Open
oyvindwe wants to merge 1 commit into
Open
Conversation
A registered callback may deregister callbacks while it runs — e.g. a Home Assistant entity tearing down during a push deregisters its own update callback. Iterating self._callbacks directly means that removal mutates the list mid-iteration and the loop skips the following callback, so some consumers can miss an update. Iterate over a snapshot (list(self._callbacks)) at both data-callback dispatch sites, matching how _set_connected already dispatches the connection-state callbacks.
oyvindwe
added a commit
to oyvindwe/home-assistant
that referenced
this pull request
Jul 14, 2026
The call_soon deferral introduced an ordering hazard: when pynobo processes a buffered zone removal followed by an id-reusing add before the deferred removal runs, the re-add is rejected as a duplicate and the stale snapshot then deletes the surviving entity, leaving the zone with no entity until reload. Synchronous removal has no such window — the old device/entity is gone before the next buffered message's add. The original re-entrancy concern (mutating pynobo's callback list mid-dispatch) is harmless here (per-message dispatch; removal messages don't update survivors) and is fixed at the root upstream in echoromeo/pynobo#44.
21 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A registered callback may deregister callbacks while it runs — e.g. a Home Assistant entity tearing down during a push deregisters its own update callback. Iterating
self._callbacksdirectly means that removal mutates the list mid-iteration and the loop skips the following callback, so some consumers can miss an update.Iterate over a snapshot (
list(self._callbacks)) at both data-callback dispatch sites, matching how_set_connectedalready dispatches the connection-state callbacks.Triggered by this comment: home-assistant/core#176511 (comment)