eclipse/paho.mqtt.c

MQTT Paho C/C++ returns disconnection after 2.5xKeepAlive

kunaltakalkar opened this issue · 2 comments

Describe the bug

I am using the following Libraries: paho.mqtt.c-1.3.13, paho.mqtt.cpp-1.3.2
I have set KeepAlive to 20secs.
If the internet is disconnected during the PUBLISH calls (small chunks of data), the connectionLost is received after ~50secs (2.5xKeepAlive).

To Reproduce

  1. Connect to the MQTT broker.
  2. Start sending messages.
  3. The Internet is disconnected during publish calls.
  4. Wait for disconnection (connectionLost)

Observed behavior
connectionLost is received after ~50 secs (2.5xKeepAlive)

Expected behavior
connectionLost should be received within 30 secs (1.5xKeepAlive)

Screenshots
NA

Log files
Logs are attached here:
Paho_Keepalive_Issue.txt

** Environment (please complete the following information):**

  • OS: Linux Docker (on Ubuntu 22.04.3 LTS (x86-64))
  • Version: 22.04.1-Ubuntu x86_64

Additional context
async_publish example was modified to simulate the behavior. Its attached to the ticket.
async_publish.cpp.txt

If you have a keepalive interval of 30 seconds, then if there is no other traffic, a PINGREQ will be sent every 30 seconds. If the connection is broken soon after a PINGREQ is sent and the PINGRESP received, it will be another 30 seconds until the next PINGREQ is sent. Then another 45 seconds before the connection is recognized as lost. So I think this is possible.

As per mqtt specification, broker follows 1.5x KeepAlive. Shouldn't that be same on the client and be consistent with the specification?
Please correct me if my understanding is wrong.