Skip to content

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.
# 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

### What is a persistent session?

A session stored by the broker across network connections. Queued messages are delivered when the client reconnects.

How long does EMQX keep sessions?

Configurable via session.lifetime in emqx.conf. Default: 2 hours. After expiry, all session data is deleted.

What happens to queued messages?

QoS 1/2 messages published while the client is offline are queued. Delivered on reconnect. Queued message count is limited.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro