Skip to content

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

### What is the default keep alive?

MQTT spec default: 60 seconds. If not specified, most libraries default to 60s. EMQX default: 120 seconds max.

What happens if keep alive expires?

The broker disconnects the client, publishes the Will message (if set), and cleans the session if Clean Session = true.

Can I disable keep alive?

No. Set a high value (e.g., 65535 seconds = ~18 hours) for effectively no keep alive. Most clients send pings anyway.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro