Skip to content

Commit

Permalink
Add clients to session expiry check list when restarting and reloadin…
Browse files Browse the repository at this point in the history
…g from persistence.

Closes #2546. Thanks to Joachim Schachermayer.
  • Loading branch information
ralight committed May 23, 2022
1 parent 147f7c8 commit 9bfa410
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ChangeLog.txt
@@ -1,3 +1,11 @@
1.6.16 - 2022-xx-xx
===================

Broker:
- Add clients to session expiry check list when restarting and reloading from
persistence. Closes #2546.


1.6.15 - 2021-06-08
===================

Expand Down
1 change: 1 addition & 0 deletions src/mosquitto_broker_internal.h
Expand Up @@ -713,6 +713,7 @@ int mosquitto_security_auth_continue(struct mosquitto_db *db, struct mosquitto *
* Session expiry
* ============================================================ */
int session_expiry__add(struct mosquitto_db *db, struct mosquitto *context);
int session_expiry__add_from_persistence(struct mosquitto_db *db, struct mosquitto *context, time_t expiry_time);
void session_expiry__remove(struct mosquitto *context);
void session_expiry__remove_all(struct mosquitto_db *db);
void session_expiry__check(struct mosquitto_db *db, time_t now);
Expand Down
2 changes: 1 addition & 1 deletion src/persist_read.c
Expand Up @@ -209,7 +209,7 @@ static int persist__client_chunk_restore(struct mosquitto_db *db, FILE *db_fptr)
}
}
}
/* FIXME - we should expire clients here if they have exceeded their time */
session_expiry__add_from_persistence(db, context, chunk.F.session_expiry_time);
}else{
rc = 1;
}
Expand Down
18 changes: 18 additions & 0 deletions src/session_expiry.c
Expand Up @@ -80,6 +80,24 @@ int session_expiry__add(struct mosquitto_db *db, struct mosquitto *context)
}


int session_expiry__add_from_persistence(struct mosquitto_db *db, struct mosquitto *context, time_t expiry_time)
{
struct session_expiry_list *item;

item = mosquitto__calloc(1, sizeof(struct session_expiry_list));
if(!item) return MOSQ_ERR_NOMEM;

item->context = context;
item->context->session_expiry_time = expiry_time;

context->expiry_list_item = item;

DL_INSERT_INORDER(expiry_list, item, session_expiry__cmp);

return MOSQ_ERR_SUCCESS;
}


void session_expiry__remove(struct mosquitto *context)
{
if(context->expiry_list_item){
Expand Down

0 comments on commit 9bfa410

Please sign in to comment.