Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOS 2 can deliver a message twice #569

Open
daisukes opened this issue Dec 16, 2023 · 0 comments
Open

QOS 2 can deliver a message twice #569

daisukes opened this issue Dec 16, 2023 · 0 comments

Comments

@daisukes
Copy link

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.

func recoverSessionBy(_ storage: CocoaMQTTStorage) {
let frames = storage.takeAll()
if(frames != nil){
guard frames!.count >= 0 else {
return
}
// Sync to push the frame to mqueue for avoiding overcommit
deliverQueue.sync {
for f in frames! {
mqueue.append(f)
}
self.storage = storage
printInfo("Deliver recover \(frames!.count) msgs")
printDebug("Recover message \(frames!)")
}

The way to reproduce the issue

  • make an instance with cleanSession = false
    self.mqtt = CocoaMQTT(clientID: clientID, host: host, port: port)
    mqtt.cleanSession = false
    
  • connect to the broker via Wi-Fi
  • record delivered messages by subscribing to the message (I used Mosquitto as the broker and subscribed by a client with paho.mqtt.cpp)
  • publish a message every second (keeps publishing while it is disconnected)
  • disconnect intentionally by disabling Wi-Fi, wait 10 seconds, and enable Wi-Fi
  • wait until the connection is recovered and it sends the all messages
  • stop

Behavior

  • My client received all the messages + duplicated messages published while the app was disconnected.

Expected

  • My client received all the messages without any duplication

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant