fix(mqtt): give each sender its own client ID by default #2214
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.45) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 420 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 93% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.362
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #2214"
general
weight: 0.35
coderabbitai[bot]
This PR gives every MQTT service its own client ID unless the URL sets one. Two senders on one broker no longer take over each other's session.
Problem
Every MQTT service connected with the client ID
shoutrrr. A broker keeps one session per client ID and disconnects a connected client when another connects with the same ID (MQTT 5, [MQTT-3.1.4-3]). Two long-lived senders on one broker, such as two programs that each notify through Shoutrrr, kept disconnecting each other, and autopaho reconnected each one. Against a local EMQX broker, two services logged 7063 "server disconnected code=142" warnings in three seconds, and some sends failed. A client ID that is not valid UTF-8, holds a null character, or is longer than 65535 bytes could not be encoded, so every connection attempt failed until the send's time ran out. The package also exportedErrPublishTimeoutandErrConnectionNotInitialized, which nothing returns.Solution
When the URL sets no
clientid, each service now choosesshoutrrrfollowed by 12 random base32 characters. That is 20 letters and digits, which every MQTT 5 broker must accept ([MQTT-3.1.3-5]). The service keeps that ID for every connection it opens, andInitializechooses a new one. The connection's debug log names the ID. An explicitclientidis used as given, so a broker that accepts only known client IDs needs one set. Leaving the ID empty for the broker to assign was rejected, because brokers may refuse it and autopaho would get a new ID on every reconnect.With a clean session, the default, no later connection resumes the session, so a graceful disconnect now asks the broker to discard it at once. Without that, each one-shot send would leave a session on the broker for the 60 seconds Shoutrrr asks for. Against EMQX, 20 one-shot sends left 20 sessions before this change and none after it. A topic or client ID that MQTT cannot encode fails when the URL is read and on each send, with
ErrInvalidTopicor the newErrInvalidClientID. The two unused errors are removed. No code outside this repository uses them. The docs say the broker must support MQTT 5, since paho.golang speaks only that version, and explain how long the broker keeps a session.Changes
ErrPublishTimeoutandErrConnectionNotInitialized<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
MQTT connections now generate a unique client ID when none is configured. The ID is reused on reconnects and can be overridden.
Connection logs now include the client ID.
Bug Fixes
Invalid client IDs are rejected, including IDs with null bytes, invalid UTF-8, or lengths exceeding MQTT’s limit.
Clean sessions now signal that session state should expire on disconnect.
Documentation
MQTT setup guidance now explains MQTT 5 broker requirements, client IDs, session behavior, and connection failures with MQTT 3.1.1-only brokers.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->