MQTT Session State Manager
MQTT Session State Manager
Inspect the broker-side session records that make MQTT reconnects reliable or risky.
MQTT Session State Manager
An MQTT connection is the live network link. An MQTT session is the remembered state tied to a ClientID. Use this workbench to inspect what the broker keeps, discards, resumes, or cleans up when IoT devices disconnect and reconnect.
Pick Sleepy sensor resume, set Session expiry to 6 h, and Step through disconnect and reconnect; then switch to New random ClientID every boot.
A stable ClientID resumes 4 queued QoS messages within the 6 h expiry, but a fresh random identity cannot reclaim that stored session.
The broker keys subscriptions and queued messages by ClientID; Clean Start and Session Expiry govern that record independently of the physical device.
Session accounting excludes broker-cluster replication, persistent-store failure, will timing, QoS retransmission races, changed authorization, resource quotas, and vendor-specific cleanup.
Trace a reconnect from the broker's point of view
Step through the sequence. Watch the session shelf, the CONNACK result, and the broker pressure signal change together.
Try common broker decisions
Change the session request
Incoming CONNECT
Broker session registry
State drawer
The ClientID matches, the request asks to resume, and the expiry window has not elapsed. The client can rely on Session Present and process queued QoS 1/2 messages.
Clean Start decides whether to begin with old state. Session Expiry decides how long state survives after disconnect.
Clean Session 1 starts clean. Clean Session 0 asks the broker to resume and store session state after disconnect.
Random ClientIDs create new shelves at the broker, so old subscriptions and queues become unreachable orphans.
If it is 0, rebuild subscriptions. If it is 1, the broker accepted an existing session for that ClientID.
Technical notes and primary sources
This workbench keeps retained messages separate because retained messages belong to topics, not to one client's session queue.
MQTT 5 allows broker discretion in some storage behavior, but portable offline reliability should use subscriptions and QoS 1 or QoS 2.
The broker closes the old connection. This can be useful for failover, but accidental duplication can kick active devices offline.
Set expiry, queue limits, and cleanup policies so abandoned devices do not consume broker memory or disk forever.
Practice prompts
Which settings let it receive QoS 1 command messages after reconnect without creating long-lived abandoned sessions?
Check Session Present first. If it is 0, the client must resubscribe instead of assuming the broker still has state.
Look for random ClientIDs, missing expiry limits, and offline queues that outlive the business value of the messages.
Use stable ClientIDs, persistent sessions, QoS 1/2 publishing, and broker limits sized for the expected outage window.