Commit ac92079
fix: prevent auto-reconnect from being killed when subscription setup fails
When the MQTT broker restarts (e.g. Victron power cycle, power outage),
paho-mqtt auto-reconnects and fires the on_connect callback. Previously,
if _setup_subscriptions() raised ANY exception during reconnection, the
_on_connect handler called client.disconnect(), which permanently killed
paho's auto-reconnect mechanism. The integration would never recover
without a manual reload.
Changes:
- Only call client.disconnect() on first-connect errors (auth failures,
connection refused). On reconnection, log the error and let paho
continue auto-reconnecting.
- Track subscription state with _subscribed flag, cleared on disconnect.
- Retry failed subscriptions from the keepalive loop (runs every 30s),
so even if subscription setup fails during reconnection, it will be
retried automatically.
- Add reconnection-specific logging (session_present flag, retry status)
for better diagnostics.
Closes #461
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6374e2f1-1fb3-453d-a1c2-dddf69a62f611 parent 578e0d6 commit ac92079
1 file changed
Lines changed: 34 additions & 3 deletions
Lines changed: 34 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| |||
414 | 415 | | |
415 | 416 | | |
416 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
417 | 422 | | |
418 | 423 | | |
419 | 424 | | |
420 | 425 | | |
421 | | - | |
422 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
423 | 436 | | |
424 | 437 | | |
425 | 438 | | |
| |||
451 | 464 | | |
452 | 465 | | |
453 | 466 | | |
454 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
455 | 475 | | |
456 | 476 | | |
457 | 477 | | |
| |||
463 | 483 | | |
464 | 484 | | |
465 | 485 | | |
| 486 | + | |
466 | 487 | | |
467 | 488 | | |
468 | 489 | | |
| |||
852 | 873 | | |
853 | 874 | | |
854 | 875 | | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
855 | 885 | | |
856 | 886 | | |
857 | 887 | | |
| |||
1040 | 1070 | | |
1041 | 1071 | | |
1042 | 1072 | | |
| 1073 | + | |
1043 | 1074 | | |
1044 | 1075 | | |
1045 | 1076 | | |
| |||
0 commit comments