eclipse / paho.mqtt.android

MQTT Android
Other
2.92k stars 883 forks source link

Cannot receive Push Message due to disconnection (No PINGREQ) #496

Open prageeth07 opened 1 year ago

prageeth07 commented 1 year ago

Please fill out the form below before submitting, thank you!

__Android API Version Bug Seen on: 30

__Android Version Bug Seen on: 11

Please also check that if you have found the bug in the Release version (1.1.1) that you check that it also exists in the Snapshot (1.1.2-SNAPSHOT) before raising a bug.

Description of Bug:

We have developed an Android application using the Paho MQTT Android Library. We have used the Mosquitto Service as the Mqtt Broker.

The Mqtt client options are as below :

mqttVersion = MqttConnectOptions.MQTT_VERSION_3_1_1
isCleanSession = true
isAutomaticReconnect = true

As per our findings, the android application sends a PING within the keepalive period set in the MQTT Client options using the Paho Library. The ping process works as expected as long as the device is connected to a USB cable.

2023-08-28T18:01:25: Received PINGREQ from [ClientId]
2023-08-28T18:01:25: Sending PINGRESP to [ClientId]

When referring the ADB logs later, we found out that as soon as the cable is disconnected, the PING has not occured as expected. There are huge time gaps between each ping and we were able to confirm it through the mosquitto broker logs as below.

When referring to mosquitto logs it seems that the android device (mqtt client) has not sent any PING requests (PINGREQ) to mosquitto. After a short time without any PING requests, mosquitto has disconnected the client. There are times that the client has been reconnected by Paho mqtt client but the reconnection time interval is not consistent.

2023-08-28T20:30:30: [ClientId] has exceeded timeout, disconnecting.
2023-08-28T20:33:16: New client connected from [IP]:[Port] as [ClientId] (p2, c0, k60, u'example').

Therefore, the PUBLISH messages are not sent to the android application as soon as it is received by mosquitto broker.

According to these findings we have come to the understanding that the PING from the android application is not sent as expected using the Paho MQTT Android Library.