Closed vshirol closed 1 year ago
Hi @vshirol - thanks for pointing this out. To be thorough could you also include the mosquito_pub
command line that you used?
Hi @vshirol - thanks for pointing this out. To be thorough could you also include the
mosquito_pub
command line that you used?
Hi @pglombardo, below is the command for publishing message from mosquitto_pub mosquitto_pub -h 127.0.0.1 -p 1893 -u username -P password -t test/duplicate/msg/ --protocol-version mqttv5 --id mosq_client-1 -m testMsg
Steps:
Let me know if you need any other details from me.
Perfect/thanks @vshirol. I'm traveling for the next few days but I'll try to get in some time to try this out myself soon.
In the meantime you could try this out against HiveMQ cloud to potentially exclude the 'VMQ' (assuming this means VerneMQ) broker from being the issue. If you don't have time, I'll do this myself once I get back to my laptop.
I'll post back soon.
Perfect/thanks @vshirol. I'm traveling for the next few days but I'll try to get in some time to try this out myself soon.
In the meantime you could try this out against HiveMQ cloud to potentially exclude the 'VMQ' (assuming this means VerneMQ) broker from being the issue. If you don't have time, I'll do this myself once I get back to my laptop.
I'll post back soon.
Yes, VMQ refers to VerneMQ here. We can rule out broker role in this issue, as we captured packets on broker port and analyzed. Let me know if you want, we can share the same.
Hi @vshirol - the issue seems to be that on each reconnect, the code is adding a new callback:
mqtt5AsyncClient.subscribeWith().topicFilter<...snip...>.callback(mqtt5Publish -> {
if (mqtt5Publish != null) {
System.out.println(...);
}
So when a message is received, it's delivered to each callback (which is equal to the number of reconnects).
One option to fix is this to check the session state on reconnect with mqttClientConnectedContext.getConnAck().isSessionPresent()
.
If the session is already present, no need to call subscribe again...
Hi @vshirol - the issue seems to be that on each reconnect, the code is adding a new callback:
mqtt5AsyncClient.subscribeWith().topicFilter<...snip...>.callback(mqtt5Publish -> { if (mqtt5Publish != null) { System.out.println(...); }
So when a message is received, it's delivered to each callback (which is equal to the number of reconnects).
One option to fix is this to check the session state on reconnect with
mqttClientConnectedContext.getConnAck().isSessionPresent()
.If the session is already present, no need to call subscribe again...
Thanks @pglombardo. I will try with the proposed solution and let you know.
Hi @vshirol - any updates on this?
Hi @vshirol - since I haven't heard back I'll close out this issue. But if you're still having issues, let me know. We can re-open if needed. Best!
threadump_before_conn_reset.zip threadump_after_2times_conn_reset.zip Hi @pglombardo The above-mentioned issue is solved with your proposed code change. Thanks. But we do see similar problem in different scenario, that is when MQTT broker terminates client connection by sending Disconnect MQTT packet to client or when connection reset occurs on client side, in this case MQTT broker is still running and not restarted.
So, in these scenarios with above mentioned code change doesn't help, client receives the duplicate message which is equal to number of times its connection reset either by broker or system error or client-side network issues. Let me know if you need any more details from my side.
From thread dump we do see, upon every connection reset there is an increase in RxComputationThreadPool instance. Attaching thread dump of both normal and after 2 times connection
Thanks, Vasant
Expected behavior
We expect MQTT client should receive only one message upon reconnect and subscribe.
Actual behavior
But client receives same message multiple times == number of times it got reconnected successfully.
To Reproduce
Below is sample client code to connect and subscribe. To reproduce after client connected successfully, stop the VMQ broker and then we see client tries to reconnect and start the VMQ broker after few mins/seconds then eventually client connects back to broker and subscribes to topic. Now publish msg only once to topic to which our client subscribed, in my tests have used mosquito_pub client as its simple to use. Once after publishing msg we see, message received multiple times == number of times it got reconnected successfully.
If you stop the client and restart, then it will be good. But issue repeats if it gets disconnected and reconnected again. Below is console output from the code, after receiving message:
Thread[RxComputationThreadPool-1,5,main] : SUBSCRIBE(): received - testMsg Thread[RxComputationThreadPool-3,5,main] : SUBSCRIBE(): received - testMsg
Steps
Explained above
Reproducer code
Details