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

karlp opened this Issue Jun 21, 2016 · 1 comment


None yet
2 participants

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;
                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;

@ralight ralight added this to the Fixes-next milestone Jun 21, 2016


This comment has been minimized.

Show comment
Hide comment

ralight Jun 21, 2016




ralight commented Jun 21, 2016


@ralight ralight closed this Jun 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment