EMQX Session State Lost on Disconnect
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about EMQX Session State Lost on Disconnect. We cover key concepts, practical examples, and best practices.
The Problem
Client session state (subscriptions, queued messages) is lost after disconnection.
Quick Fix
Wrong
mqttx sub -t sensor/# --no-clean-session # Clean session overflow
Session cleared every connection.
Right
# MQTT 5.0 — Session Expiry Interval
mqttx sub -t sensor/# -h broker -p 1883 \
-u user -P pass \
--session-expiry-interval 3600
# MQTT 3.1.1 — Clean Session = false
mqttx sub -t sensor/# -h broker -p 1883 \
-u user -P pass \
-i persistent-client --clean-session false
# EMQX config
# session.lifetime = 2h # Default 2 hours
Session persists across reconnections — subscriptions and queued messages preserved.
Prevention
In MQTT 3.1.1, set Clean Session = false. In MQTT 5.0, set Session Expiry Interval > 0. Session includes: subscriptions, queued QoS 1/2 messages, and will message. Sessions are identified by Client ID (must be consistent). EMQX persists sessions based on session.lifetime config.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro