hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
824 stars 153 forks source link

Messages lost when using both MQTTv3 and MQTTv5 clients in async mode #618

Open inad9300 opened 4 months ago

inad9300 commented 4 months ago

🐛 Bug Report

I have a setup where I receive messages from a MQTTv5 broker at a rate of one per second, and have to forward them to a MQTTv3 broker. As such, I have a software component with two clients, one connected to each broker, using the asynchronous API flavor.

In this scenario, the MQTTv5 client receives all messages well, but sending those same messages through the MQTTv3 client behaves in such a way that the sending of 8 consecutive messages works, then the 9th times out, repeatedly.

🔬 How To Reproduce

I have added a test case reproducing the problem in https://github.com/hivemq/hivemq-mqtt-client/pull/619. It shows how the reactive API flavor handles the task well, whereas the asynchronous one is only able to send a few messages before breaking. I have not added a test using the blocking API, but I have been able to test it in my own project and it works too.

I believe the same problem exists when going from MQTTv3 to MQTTv5. Perhaps the version does not matter. I also don't know if two async clients are necessary to reproduce the issue. These are all tests worth doing and automating, in my opinion.

Environment

Ubuntu 22.04.

📈 Expected behavior

All messages should arrive, as is the case with the other API flavors.

SgtSilvio commented 4 months ago

In your PR I commented on your test to explain why you run into this behavior. It is basically caused by a threading problem in the test code and is not an issue of the library. Feel free to comment and ask for clarifications.

inad9300 commented 4 months ago

Could you please reopen this until fully solved? I fear it'll go unnoticed otherwise.

pglombardo commented 4 months ago

Hi @inad9300 - you're right - we'll close this issue after the discussion in #619 is complete. @SgtSilvio should loop back soon.