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 80b3691 commit c99502a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -11,6 +11,8 @@ Broker:
required for MQTT v3.1. Closes #2522.
- Improve documentation of `persistent_client_expiration` option.
Closes #2404.
- Add clients to session expiry check list when restarting and reloading from
persistence. Closes #2546.

Client library:
- Fix threads library detection on Windows under cmake. Bumps the minimum
Expand Down
1 change: 1 addition & 0 deletions src/mosquitto_broker_internal.h
Expand Up @@ -818,6 +818,7 @@ void unpwd__free_item(struct mosquitto__unpwd **unpwd, struct mosquitto__unpwd *
* Session expiry
* ============================================================ */
int session_expiry__add(struct mosquitto *context);
int session_expiry__add_from_persistence(struct mosquitto *context, time_t expiry_time);
void session_expiry__remove(struct mosquitto *context);
void session_expiry__remove_all(void);
void session_expiry__check(void);
Expand Down
2 changes: 1 addition & 1 deletion src/persist_read.c
Expand Up @@ -208,7 +208,7 @@ static int persist__client_chunk_restore(FILE *db_fptr)
}
}
}
/* FIXME - we should expire clients here if they have exceeded their time */
session_expiry__add_from_persistence(context, chunk.F.session_expiry_time);
}else{
rc = 1;
}
Expand Down
17 changes: 17 additions & 0 deletions src/session_expiry.c
Expand Up @@ -82,6 +82,23 @@ int session_expiry__add(struct mosquitto *context)
}


int session_expiry__add_from_persistence(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 c99502a

Please sign in to comment.