fix(discovery): clean up stuck discovery_running on probe failure (audit companion)#457
Merged
Conversation
…dit companion) Companion to nikobus-connect#119 (discovery audit). In _try_pclink_inventory, the CancelledError path cleared discovery_running and set the finished event, but the generic-exception path returned False with NO cleanup. The library sets discovery_running=True before the point where start_inventory_discovery can raise (not connected, send failure) — so a probe failure left the flag stuck True: polling suppressed forever and every new scan rejected as 'discovery already running'. The except path now mirrors the CancelledError cleanup. (0.27.1 also resets library-side; this is the integration's defence in depth for older library versions.) +1 regression test. 436 passed, ruff clean, mypy 100 (= baseline). https://claude.ai/code/session_01LH7yGDY8ttvZUVMVjfSNXj
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.
Summary
Companion to nikobus-connect #119 (discovery-process audit) — the HA side of the same stuck-flag bug, found independently during my own read of
discovery_mixin.py.In
_try_pclink_inventory, theCancelledErrorpath cleareddiscovery_runningand set the finished event — but the generic-exception path returnedFalsewith no cleanup. The library setsdiscovery_running=Truebefore the point wherestart_inventory_discoverycan raise (not connected, send failure), so a probe failure left the flag stuck True: polling suppressed forever (_async_update_dataearly-returns) and every new scan rejected as "discovery already running". Only an HA restart recovered.The except path now mirrors the CancelledError cleanup. (0.27.1 also resets library-side on that path — this is the integration's defence in depth for older library versions, and the pin stays
>=0.27.0.)Verification
+1 regression test (probe raises after the library set the flag → flag cleared, event set, fallback still runs).
436 passed,ruffclean,mypy100 (= baseline).Independent of #119 — both can merge in any order; publishing 0.27.1 to PyPI after #119 merges gets the library-side fixes to new installs automatically (no pin bump needed).
https://claude.ai/code/session_01LH7yGDY8ttvZUVMVjfSNXj
Generated by Claude Code