Commit 0df6a30
Fix boot race condition: catch NotConnectedError and stop leaked paho threads
When HA and Victron boot simultaneously after a power outage, several
failure paths can occur:
1. NotConnectedError escapes Hub.start() uncaught — HA treats this as a
permanent failure (no retry), so the integration never recovers.
Fix: catch NotConnectedError in Hub.start() and raise ConfigEntryNotReady
so HA retries with exponential backoff.
2. Paho MQTT thread leak — connect() calls loop_start() early, but if any
subsequent step fails (timeout, connection drop, etc.), loop_stop() is
never called. Each HA retry creates a new Hub, leaking the old thread.
Fix: wrap post-loop_start() code in try/except that calls loop_stop()
on failure.
3. disconnect() doesn't call loop_stop() — the background thread started
by loop_start() is never explicitly stopped.
Fix: add loop_stop() call in disconnect().
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6374e2f1-1fb3-453d-a1c2-dddf69a62f611 parent ac92079 commit 0df6a30
2 files changed
Lines changed: 21 additions & 8 deletions
Lines changed: 16 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
379 | 386 | | |
380 | 387 | | |
381 | 388 | | |
| |||
839 | 846 | | |
840 | 847 | | |
841 | 848 | | |
| 849 | + | |
842 | 850 | | |
843 | 851 | | |
844 | 852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
| |||
0 commit comments