eclipse-paho / paho.mqtt.c

An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/
https://eclipse.org/paho
Other
1.97k stars 1.1k forks source link

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

Open kunaltakalkar opened 8 months ago

kunaltakalkar commented 8 months ago

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):

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

icraggs commented 8 months ago

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.

kunaltakalkar commented 8 months ago

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.