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

duplicate $SYS messages in store in certain cases #191

Closed
karlp opened this issue Jun 21, 2016 · 1 comment
Closed

duplicate $SYS messages in store in certain cases #191

karlp opened this issue Jun 21, 2016 · 1 comment

Comments

@karlp
Copy link
Contributor

karlp commented Jun 21, 2016

with 1.4.9, the following sequence results in a duplicating $SYS messages in the persistent store.

  • at least one subscriber to $SYS/# must have existed/exist at db persistence time? (I just used mosquitto_sub and left it running, without this, you don't get the problem)
  • subscriber must have been susbcribed long enough to get an updated message, not just the initial messages.

stop mosquitto and restart, wait for update on topic again.

The following patch, suggested by @ralight fixes the issue. (though you still end up with a single copy of them even if the subscriber is gone by the time you save the db on exit, and even if the subscriber was clean session=true)

diff --git a/src/persist.c b/src/persist.c
index d71fc04..f416aea 100644
--- a/src/persist.c
+++ b/src/persist.c
@@ -140,7 +140,7 @@ static int mqtt3_db_message_store_write(struct mosquitto_db *db, FILE *db_fptr)
        stored = db->msg_store;
        while(stored){
                if(stored->topic && !strncmp(stored->topic, "$SYS", 4)){
-                       if(stored->ref_count == 1 && stored->dest_id_count == 0){
+                       if(stored->ref_count <= 1 && stored->dest_id_count == 0){
                                /* $SYS messages that are only retained shouldn't be persisted. */
                                stored = stored->next;
                                continue;
ralight added a commit that referenced this issue Jun 21, 2016
@ralight ralight added this to the Fixes-next milestone Jun 21, 2016
@ralight
Copy link
Contributor

ralight commented Jun 21, 2016

Thanks

@ralight ralight closed this as completed Jun 21, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants