You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reconnect edge cases: same-tick double trigger, and unload during an in-executor connect #14
Found reviewing #13 (#11). Both bugs reproduce on main. Neither has been seen live yet.
1. Same-tick double trigger cancels a running forced attempt
When a sleeping retry is preempted, mqtt_retry_sleeping stays True until that task's finally runs. A second _trigger_mqtt_reconnect in the same loop iteration (watchdog, reconnect-failed, credential refresh) then cancels the forced attempt that just started (api.py ~1268-1272). Cost: a duplicate auth request and a wasted attempt. #13 adds a third trigger source, so the odds go up.
2. Unload during an in-executor connect leaves a live client and recreates the store
Cancelling the reconnect task doesn't stop _connect_mqtt in the executor thread. When that thread finishes, _schedule_credential_refresh -> _get_entry_store recreates the entry store (api.py ~1376), and the MQTT client stays connected after unload.
Acceptance
A deterministic test for each bug that fails on main.
Only one attempt runs after a preempt plus a same-tick trigger.
After unload, nothing recreates the store and the client is disconnected.
Probe shapes K and I2 are in the #13 review scratch (test_probe_review11_r2.py).
Another unload edge case, found in review of PR #13 (credential-refresh reconnect self-cancel). It was already on main before that PR and is out of scope for it.
_connect_mqtt calls _get_entry_store, whose setdefault brings back an empty store in hass.data if the entry was unloaded while a connect was in flight. In production, cleanup_entry cancels the attempt first, so this needs an unload that skips cleanup. A reviewer probe (L3b) reproduces it.
Fix direction: use a non-creating lookup (hass.data.get) on every path that can run after unload, the same way _wake_held_write_on_reconnect already does.
Activity
abrainwood commentedon Sep 15, 2026
Another unload edge case, found in review of PR #13 (credential-refresh reconnect self-cancel). It was already on main before that PR and is out of scope for it.
_connect_mqttcalls_get_entry_store, whosesetdefaultbrings back an empty store inhass.dataif the entry was unloaded while a connect was in flight. In production,cleanup_entrycancels the attempt first, so this needs an unload that skips cleanup. A reviewer probe (L3b) reproduces it.Fix direction: use a non-creating lookup (
hass.data.get) on every path that can run after unload, the same way_wake_held_write_on_reconnectalready does.