Skip to content

enhancement: robust MQTT auto-reconnect with exponential backoff#4963

Open
theKorzh wants to merge 4 commits intomeshtastic:mainfrom
theKorzh:enahcement/mqtt-auto-reconnect
Open

enhancement: robust MQTT auto-reconnect with exponential backoff#4963
theKorzh wants to merge 4 commits intomeshtastic:mainfrom
theKorzh:enahcement/mqtt-auto-reconnect

Conversation

@theKorzh
Copy link
Copy Markdown
Contributor

@theKorzh theKorzh commented Mar 31, 2026

Fixes MQTT connection loss without automatic reconnection. Previously, the app made no reconnection attempts after MQTT connection loss. When the connection dropped, the MQTT Proxy would silently stop working, and the app would never attempt to reconnect — requiring users to manually restart the app or reconnect node. This PR implements a infinite reconnection retry loop with exponential backoff.

Why This Implementation Is Necessary

The KMQTT library does NOT have built-in auto-reconnect functionality.

As confirmed by the library owner in issue #51:

"auto-reconnect is something I want to implement but I am not sure when I will be able to do it. In the meantime it's possible to obtain a similar behaviour by creating a new client object every time."

This PR provides the auto-reconnect functionality that the library itself does not yet offer.

Possible fixes: #4016 and related MQTT reconnection issues.

@theKorzh theKorzh closed this Mar 31, 2026
@theKorzh theKorzh reopened this Mar 31, 2026
@jamesarich
Copy link
Copy Markdown
Collaborator

This will need to be rebased onto main before I can consider reviewing. I like the idea of it though. 👍

@theKorzh theKorzh force-pushed the enahcement/mqtt-auto-reconnect branch from b26eca8 to 9ddf973 Compare April 1, 2026 01:36
@theKorzh
Copy link
Copy Markdown
Contributor Author

theKorzh commented Apr 1, 2026

Rebased onto latest main. Should be ready for review now.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 0% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.76%. Comparing base (7c9d007) to head (9ddf973).

Files with missing lines Patch % Lines
...stic/core/network/repository/MQTTRepositoryImpl.kt 0.00% 91 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4963      +/-   ##
==========================================
- Coverage   19.81%   19.76%   -0.06%     
==========================================
  Files         575      575              
  Lines       18926    18974      +48     
  Branches     2825     2832       +7     
==========================================
  Hits         3750     3750              
- Misses      14615    14663      +48     
  Partials      561      561              
Flag Coverage Δ
host-unit 19.76% <0.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...stic/core/network/repository/MQTTRepositoryImpl.kt 0.00% <0.00%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MQTT broker timeout

2 participants