emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.6k stars 420 forks source link

QOS 2 can deliver a message twice #569

Open daisukes opened 9 months ago

daisukes commented 9 months ago

Hello,

I have experienced an issue where my app delivers a message twice when the app has a disconnection/reconnection, even if I set the message QOS to 2. I want to send a message every second and deliver all the messages even if the phone is disconnected for a while.

If I set cleanSession to True, it looks like the app cleans the queue and loses some messages. If I set cleanSession to False, I got the issue.

I found that recoverSessionBy enqueues stored messages and can duplicate messages. I think it should check if the mqueue already holds the same message when a stored message is appended.

https://github.com/emqx/CocoaMQTT/blob/ff7c07b8a212e2e724d93a91d165a899df546db0/Source/CocoaMQTTDeliver.swift#L78-L94

The way to reproduce the issue

Behavior

Expected

Thank you!