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

Mosquitto stops publishing when using persistent connections with QoS2 #1322

Closed
yschroeder opened this issue Jun 27, 2019 · 3 comments

Comments

@yschroeder
Copy link

commented Jun 27, 2019

Ok, I have something very hard to reproduce and I do not know how to reproduce it reliably yet:

Sometimes, when a client publishes a retained message to a topic that already has a retained message the new message is published but the old retained message stays retained. Example:

retained message "foo" on topic "test"
A subscribes to "test", receives "foo"
B publishes "bar" to "test" as retained message
A receives "bar"
A receives "foo" (again?!)
C subscribes to "test", receives "foo" (should receive "bar")

I do not know exactly yet what is going on here, it dos not always happen in my setup. I was not able to reproduce it with a minimal example.

B is a persistent client with LWT set.
In my real test the message sent by B is rather large (some kilobytes)
All messages are published and subscribed with QoS=2.
Everything in running on localhost.
Mosquitto is v1.6.3 on Arch Linux.

To me it looks like some race condition that I cannot trigger reliably.

@yschroeder

This comment has been minimized.

Copy link
Author

commented Jul 5, 2019

Ok, I found a way to reproduce this (after 4 hours of debugging and finding a minimum example):

# restart mosquitto
sudo systemctl restart mosquitto.service

# listen on topic1
mosquitto_sub -t "topic1"

# publish to topic1 without clean session
mosquitto_pub -t "topic1" -q 2 -c --id "foobar" -m "message1"
# message1 on topic1 is received as expected

# publish to topic2 without clean session
# IMPORTANT: no subscription to this topic is present on broker!
mosquitto_pub -t "topic2" -q 2 -c --id "foobar" -m "message2"
# this goes nowhere, as no subscriber present

# publish to topic1 without clean session
mosquitto_pub -t "topic1" -q 2 -c --id "foobar" -m "message3"
# message3 on topic1 IS NOT RECEIVED

# listen on topic2 
mosquitto_sub -t "topic2"

# publish to topic1 without clean session
mosquitto_pub -t "topic1" -q 2 -c --id "foobar" -m "message4"
# message2 on topic2 is received (WHAT THE F**K?)

# publish to topic1 without clean session
mosquitto_pub -t "topic1" -q 2 -c --id "foobar" -m "message5"
# message5 on topic1 is received as expected (message4 was dropped)

Basically, when you use persistent connections -c with QoS2 -q 2 and you publish to a topic without subscriber, shit hits the fan. Big time.

Mosquitto version: 1.6.3

@yschroeder yschroeder changed the title Mosquitto sometimes does not update retained message Mosquitto stops publishing when using persistent connections with QoS2 Jul 5, 2019

@yschroeder

This comment has been minimized.

Copy link
Author

commented Jul 6, 2019

@ralight It would be very nice if you could address this in 1.6.4 as it is a breaking bug for our application.

Our workaround currently is to have some client listen to topic #, to ensure that there is a subscriber on every topic.

By the way, this is a proper "Heisenbug": It only happens when you are not trying to figure out what happens (no subscriber present)...

ralight added a commit that referenced this issue Jul 31, 2019

Fix incoming msgs not being removed when there are no subs
Fix incoming messages not being removed for a client if the topic being
published to does not have any subscribers.

Closes #1322. Thanks to Yannic Schröder.
@ralight

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2019

Thank you for the very straightforward path to follow and the effort to create it! It took a bit of figuring out, but I believe this is now fixed in the fixes branch and will be part of 1.6.4 shortly.

I spent a year in Braunschweig a fair few years ago, it's a nice place.

@ralight ralight added this to the 1.6.4 milestone Aug 1, 2019

@ralight ralight closed this Aug 1, 2019

vankxr added a commit to vankxr/mosquitto that referenced this issue Aug 9, 2019

Fix incoming msgs not being removed when there are no subs
Fix incoming messages not being removed for a client if the topic being
published to does not have any subscribers.

Closes eclipse#1322. Thanks to Yannic Schröder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.