[x] Bug exists Release Version 1.2.5 ( Master Branch)
[x] Bug exists in MQTTv3 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
[ ] Bug exists in MQTTv5 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
Reproduction steps
create a sub client(subscribing to a topic in the connectComplete callback)
public void connectComplete(boolean reconnect, String serverURI) { myClient.subscribe(this.topic); }
and create a pub client
the pub client continuously publishes messages.
the sub client receive messages
then, close the sub client whille the pub client continues to publish message, ensuring that the pub client still published more than 10 message
now, the sub client session(in broker) has more than 10 unconsumed messages
close the pub client, reconnect the sub client(sub client id must unchanged)
finally, the sub client will be blocked until the checkForActivity method closes the client
���� 11, 2023 5:22:46 ���� org.eclipse.paho.client.mqttv3.internal.ClientState checkForActivity
����: client1: Timed out as no activity, keepAlive=15,000,000,000 lastOutboundActivity=202,748,527,866,900 lastInboundActivity=202,733,513,164,800 time=202,763,529,941,000 lastPing=202,748,527,900,000
on connectionLost
More Information
the checkForActivity Method closes the client because that client was not received MqttPingResp(ping response)
additionally, I've discovered that subscribe ack(MqttSuback) was not recevied either
however, ping ack and sub ack both had been sent by the broker(EMQX Broker)
the sub client can recevied 10 message from broker when reconnecting(debug can found it, but did not send message ack)
Based on further speculation
the sub client hadn't received ping ack and sub ack
the status of the Rec Thread(CommsReceiver) may be in WAITING state
Reason analysis
Paho Mqtt Thread
CommsReceiver(receive message from broker)
CommsCallback(consume message)
CommsSender(publish meesage)
Client startup process (coarse-grained):
connect packet sent
connect ack recevied
received message from broker if need
the connectComplete called
subscribe a topic in the connectComplete, and then the CallThread(CommsCallback) will wait until it gets sub ack notified
Rec Thread(CommsReceiver) Part
connect ack received
received message from broker(more than 10 messages)
put the messages in the CommsCallback.messageQueue
The important logic is coming:clientState.notifyReceivedMsg(message)Rec Thread(CommsReceiver) will wait when messageQueue.size() >= 10
Conclusion
**1. The Call Thread(CommsCallback) state in WAITING when subscribe in the connectComplete
The Rec Thread(CommsReceiver) state in WAITING when CommsCallback.messageQueue size >= 10
The CommsCallback.messageQueue consumed in Call Thread(CommsCallback), but Call Thread(CommsCallback) state in WAITING now
The Rec Thread(CommsReceiver) state in WAITING, Thus Ping Ack and Sub Ack are never received.
Based on the above point, The Call Thread(CommsCallback) will not be notified
Reproduction steps
public void connectComplete(boolean reconnect, String serverURI) { myClient.subscribe(this.topic); }
and create a pub clientcheckForActivity
method closes the clientMore Information
checkForActivity
Method closes the client because that client was not received MqttPingResp(ping response)Based on further speculation
Reason analysis
Paho Mqtt Thread
Client startup process (coarse-grained):
connectComplete
calledconnectComplete
, and then the CallThread(CommsCallback) will wait until it gets sub ack notifiedRec Thread(CommsReceiver) Part
CommsCallback.messageQueue
clientState.notifyReceivedMsg(message)
Rec Thread(CommsReceiver) will wait whenmessageQueue.size()
>= 10Conclusion
**1. The Call Thread(CommsCallback) state in WAITING when subscribe in the
connectComplete
CommsCallback.messageQueue
size >= 10CommsCallback.messageQueue
consumed in Call Thread(CommsCallback), but Call Thread(CommsCallback) state in WAITING nowPingTask
will close the client**