Skip to content

Commit

Permalink
Fix retained messages with an expiry interval not being expired.
Browse files Browse the repository at this point in the history
This happened after being restored from persistence.

Closes #1464. Thanks to Dustin Sallings.
  • Loading branch information
ralight committed Oct 31, 2019
1 parent e6e7fc9 commit 06a27e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions src/persist_read.c
Expand Up @@ -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.");
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 06a27e7

Please sign in to comment.