Fix retained messages with an expiry interval not being expired.

This happened after being restored from persistence.

Closes #1464. Thanks to Dustin Sallings.
pull/1485/head
Roger A. Light 6 years ago
parent e6e7fc961d
commit 06a27e799f

@ -9,6 +9,8 @@ Broker:
Closes #1442. Closes #1442.
- Fix problems with reloading config when `per_listener_settings` was true. - Fix problems with reloading config when `per_listener_settings` was true.
Closes #1459. Closes #1459.
- Fix retained messages with an expiry interval not being expired after being
restored from persistence. Closes #1464.
Client library: Client library:
- Fix publish properties not being passed to on_message_v5 callback for QoS 2 - Fix publish properties not being passed to on_message_v5 callback for QoS 2

@ -114,6 +114,12 @@ static int persist__client_msg_restore(struct mosquitto_db *db, struct P_client_
struct mosquitto *context; struct mosquitto *context;
struct mosquitto_msg_data *msg_data; 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)); cmsg = mosquitto__calloc(1, sizeof(struct mosquitto_client_msg));
if(!cmsg){ if(!cmsg){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory."); 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->dup = chunk->F.retain_dup&0x0F;
cmsg->properties = chunk->properties; 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; cmsg->store = load->store;
db__msg_store_ref_inc(cmsg->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){ if(chunk.F.expiry_time > 0){
message_expiry_interval64 = chunk.F.expiry_time - time(NULL); message_expiry_interval64 = chunk.F.expiry_time - time(NULL);
if(message_expiry_interval64 < 0 || message_expiry_interval64 > UINT32_MAX){ 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{ }else{
message_expiry_interval = (uint32_t)message_expiry_interval64; 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){ if(load){
sub__messages_queue(db, NULL, load->store->topic, load->store->qos, load->store->retain, &load->store); sub__messages_queue(db, NULL, load->store->topic, load->store->qos, load->store->retain, &load->store);
}else{ }else{
log__printf(NULL, MOSQ_LOG_ERR, "Error: Corrupt database whilst restoring a retained message."); /* Can't find the message - probably expired */
return MOSQ_ERR_INVAL;
} }
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
} }

Loading…
Cancel
Save