EMQX Client Keep Alive Timeout Disconnections
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about EMQX Client Keep Alive Timeout Disconnections. We cover key concepts, practical examples, and best practices.
The Problem
EMQX disconnects clients due to keep alive timeout even when they are active.
Quick Fix
Wrong
new MqttClient('broker', 1883, 20).connect() # Keep alive too short
Broker disconnects client after 20 seconds of inactivity.
Right
# MQTT keep alive set to 60 seconds
mqttx sub -t test -h broker -p 1883 -k 60
# EMQX config for max keep alive
# zone.default.keepalive_backoff = 1.5 # 1.5x multiplier
# zone.default.max_keepalive = 120 # Maximum allowed
# Client-side reconnect on timeout
client.on('disconnect', () => {
console.log('Disconnected, reconnecting...')
setTimeout(() => client.reconnect(), 5000)
})
Client stays connected within keep-alive window. 60-second interval with no pings necessary.
Prevention
Set keep alive to 30-120 seconds based on network reliability. The broker allows 1.5x the keep-alive interval (backoff). Send PINGREQ within the keep-alive interval, even with no data. EMQX has max_keepalive to prevent abuse. Implement auto-reconnect in clients.
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