Repository navigation
Re-arm the MQTT reconnect log gate on a granted SUBACK, not on CONNACK - #2960
Conversation
|
ESPHome Bot (@esphbot) review |
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2960 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 300 300
Lines 26429 26429
=======================================
Hits 26367 26367
Misses 62 62
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
There was a problem hiding this comment.
🟡 Changes recommended
The persistent-denial regression test bypasses the original faulty reset point and would still pass if that bug were restored.
1 open issue
What changed in this PR
This PR adjusts the MQTT discovery monitor’s reconnect logging so persistent subscription denials warn once, while a working subscription re-arms warnings for a later outage.
Changes:
- Move log-gate re-arming from connection acceptance to a granted discovery subscription.
- Rename the session flag to reflect subscription success.
- Add and update tests for subscription denial and warning-reset behavior.
| File | Description |
|---|---|
tests/test_mqtt_monitor.py |
Adds subscription log-gate tests and updates outage-reset coverage. |
esphome_device_builder/controllers/_device_mqtt_monitor.py |
Re-arms reconnect warnings only after a granted SUBACK. |
Review effort: Balanced
…he rationale comments
|
ESPHome Bot (@esphbot) review Applied in 901f6e7: the denial test now leaves |
There was a problem hiding this comment.
🟢 Approval recommended
The narrow change preserves outage warnings while suppressing repeated subscription-denial warnings, with focused regression coverage and no unresolved findings.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
Confirmed resolved. SUBACK denial now fires from |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
ESPHome Bot (@esphbot) review c3302db fixes the Pytest (ubuntu / 3.12) timeout on the previous head: with a zero reconnect delay the fake kept the session failing in a tight loop, and the cancel from |
PR Review — Re-arm the MQTT reconnect log gate on a granted SUBACK, not on CONNACKReady to merge. The flake fix in c3302db is sound, and I found no new issues.
I couldn't run pytest in this review shell. The 25-run stability claim and the claim that the test fails on main are the author's own results; reading the code supports both. Checklist
Automated review by Kōan (Claude) |
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.

What does this implement/fix?
A broker that accepts the connection but denies the
esphome/discover/#subscription made the monitor log the same WARNING on every 5 second reconnect forever, because the quiet-log gate was re-armed by the CONNACK that preceded each denial; the gate now re-arms only on a granted SUBACK, so a persistent denial warns once and then collapses to DEBUG like a rejected CONNACK already does.MQTT broker ... unreachable (subscription denied ...)WARNING per streak, with the repeats at DEBUG; a real outage after a working session still re-warns, since a granted SUBACK re-arms the gate exactly as the CONNACK used to.Mechanism
_runloops_connect_and_listenand calls_log_reconnect_failureon every failure. That method logs loudly only while_connect_error_loggedis clear, and clears it when the failed iteration had set the "this session connected" flag. The flag was set immediately after a successful CONNACK, before the SUBACK verdict. A denial therefore ran: CONNACK ok (flag set) → SUBACK 0x80 →ConnectionError("subscription denied ...")→ gate re-armed → WARNING, every_RECONNECT_DELAY. A rejected CONNACK never set the flag, which is why that case already collapsed to DEBUG.Moving the set into
require_suback, aftersignals.subscribedfires, keeps every other property: the re-arm still happens inside the iteration (not on a clean return, which production rarely sees because the TaskGroup parks), and it happens once per granted handshake, including paho's own auto-reconnect SUBACKs, so the down → up → down case still warns twice (test_run_resets_log_gate_after_granted_suback, formerly..._after_successful_connect).The
MQTT connected to ...INFO line still appears on each reconnect in the denial loop; it is accurate (the broker did accept the connection) and matches what a flapping broker logs, so it is left alone.Verification
pytest tests/test_mqtt_monitor.py: 145 passed;pytest tests/e2e/slow/mqtt(real mosquitto): 4 passed; mypy clean on the monitor; pre-commit clean.Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.index.json/definitions/components/*.jsonhave not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.