fix(mqtt): make the MQTT client-id unique per connection#5755
Merged
jamesarich merged 1 commit intoJun 9, 2026
Conversation
The proxy/probe client-id was "MeshtasticAndroidMqttProxy-$myId", where
myId is the node id and is null ("unknown") until the local node record
loads. That is not unique per client: clients sharing a node id — and the
whole "unknown" pool on the public broker — present identical client-ids.
A broker evicts the previous holder (SESSION_TAKEN_OVER) when a duplicate
id connects, producing the reconnect storms behind the top io.ktor
TLS-write crash on 2.7.14.
Append a per-connection random Uuid suffix at each MqttClient/probe
construction (captured for the client's lifetime, so auto-reconnects stay
stable; a replacement client after a flap gets a fresh id). cleanStart is
true, so no durable session is lost.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Append a per-connection random
Uuidsuffix to the MQTT proxy/probe client-id.Why
The client-id was
MeshtasticAndroidMqttProxy-$myId(and…Probe-$myId), wheremyIdis the node id — and isnull→ the literalunknownuntil the local node record loads. That isn't unique per connecting client:MeshtasticAndroidMqttProxy-unknown, so on the public broker they continuously evict one another.When a duplicate client-id connects, the broker evicts the previous holder with
SESSION_TAKEN_OVER(0x8E); the two clients take the session back and forth — a reconnect storm. That storm is the trigger for the topio.ktorTLS-write crash on 2.7.14 (fixed independently in themqtt-clientlibrary — this removes the trigger).A radio only accepts one app connection at a time, so there is never a legitimate case for two clients to share an id — making a unique suffix unambiguously safe.
Change
MQTTRepositoryImpl(proxy) andMqttManagerImpl(probe): append-${Uuid.random()}to the client-id. Generated once perMqttClient/probe construction, so the id is captured for that client's lifetime — auto-reconnects keep the same id (no self-eviction), while a brand-new client after a flap gets a fresh one.cleanStart = true(unchanged default), so there is no durable session to preserve — a per-connection id is fine and avoids a stable broker-trackable identifier.MQTTRepositoryImplTest: assert the client-id prefix instead of exact equality.Testing
spotlessCheck detekt kmpSmokeCompile :core:network:allTests :core:data:allTestsall pass.🤖 Generated with Claude Code