diff --git a/ChangeLog.txt b/ChangeLog.txt index 3ed84e05..acdaf0e4 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,8 @@ Broker: Closes #1442. - Fix problems with reloading config when `per_listener_settings` was true. Closes #1459. +- Fix retained messages with an expiry interval not being expired after being + restored from persistence. Closes #1464. Client library: - Fix publish properties not being passed to on_message_v5 callback for QoS 2 diff --git a/src/persist_read.c b/src/persist_read.c index 48437e46..9613b059 100644 --- a/src/persist_read.c +++ b/src/persist_read.c @@ -114,6 +114,12 @@ static int persist__client_msg_restore(struct mosquitto_db *db, struct P_client_ struct mosquitto *context; struct mosquitto_msg_data *msg_data; + HASH_FIND(hh, db->msg_store_load, &chunk->F.store_id, sizeof(dbid_t), load); + if(!load){ + /* Can't find message - probably expired */ + return MOSQ_ERR_SUCCESS; + } + cmsg = mosquitto__calloc(1, sizeof(struct mosquitto_client_msg)); if(!cmsg){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory."); @@ -131,12 +137,6 @@ static int persist__client_msg_restore(struct mosquitto_db *db, struct P_client_ cmsg->dup = chunk->F.retain_dup&0x0F; cmsg->properties = chunk->properties; - HASH_FIND(hh, db->msg_store_load, &chunk->F.store_id, sizeof(dbid_t), load); - if(!load){ - mosquitto__free(cmsg); - log__printf(NULL, MOSQ_LOG_ERR, "Error restoring persistent database, message store corrupt."); - return 1; - } cmsg->store = load->store; db__msg_store_ref_inc(cmsg->store); @@ -273,7 +273,13 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp if(chunk.F.expiry_time > 0){ message_expiry_interval64 = chunk.F.expiry_time - time(NULL); if(message_expiry_interval64 < 0 || message_expiry_interval64 > UINT32_MAX){ - message_expiry_interval = 0; + /* Expired message */ + mosquitto__free(chunk.source.id); + mosquitto__free(chunk.source.username); + mosquitto__free(chunk.topic); + UHPA_FREE(chunk.payload, chunk.F.payloadlen); + mosquitto__free(load); + return MOSQ_ERR_SUCCESS; }else{ message_expiry_interval = (uint32_t)message_expiry_interval64; } @@ -327,8 +333,7 @@ static int persist__retain_chunk_restore(struct mosquitto_db *db, FILE *db_fptr) if(load){ sub__messages_queue(db, NULL, load->store->topic, load->store->qos, load->store->retain, &load->store); }else{ - log__printf(NULL, MOSQ_LOG_ERR, "Error: Corrupt database whilst restoring a retained message."); - return MOSQ_ERR_INVAL; + /* Can't find the message - probably expired */ } return MOSQ_ERR_SUCCESS; }