duplicate $SYS messages in store in certain cases #191

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

Projects

None yet

2 participants

@karlp
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 ralight added this to the Fixes-next milestone Jun 21, 2016
@ralight
Contributor
ralight commented Jun 21, 2016

Thanks

@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