Repository navigation
Unsubscribe dispatcher and update listeners on remove/unload - #532
Open
andreaslindroos wants to merge 1 commit into
Open
andreaslindroos wants to merge 1 commit into
andreaslindroos wants to merge 1 commit into
Conversation
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.
What's broken
Every config entry reload leaks the old sensors. They are removed from HA,
but they keep recalculating on every quarter-hour tick. With enough leaked
sensors this blocks the event loop and freezes all of HA for minutes at a
time: automations, UI and integrations all stop.
It fails silently. Nothing is logged: no error, no warning, and HA's
blocking-call detection doesn't catch CPU-bound work. All you see is HA
going unresponsive every 15 minutes, with MQTT clients timing out as a side
effect, and nothing pointing at nordpool. This also affects automations and many
probably have automations running at exact hour or half past or similar.
Why
async_added_to_hasscallsasync_dispatcher_connectfor NEW_DAY,NEW_PRICE and NEW_HOUR and discards the unsubscribe callbacks, so
removed sensors stay subscribed.
async_reload_entrycallsunload/setup directly. Listeners stack up and later updates trigger
several reloads, each leaking more sensors.
Example of this happening
HA froze for ~2 min at every :00/:15/:30/:45, with nothing in the logs.
Stack dumps showed the event loop in
handle_new_hr→_update→_calc_pricefor the whole freeze. One render takes ~0.3 ms, but therewere 133 live sensor objects for 3 real sensors.
Fix
self.async_on_remove(...).entry.async_on_unload(...).hass.config_entries.async_reload(entry.entry_id).Tested: after a restart with this patch, the
nordpool_update_hoursubscriber count stays at 3 across reloads, and the freezes are gone.