From 891be8c2fe0b68dda327b2ebc09342f72ad8018d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 11 Mar 2021 19:57:51 +0000 Subject: [PATCH] Fix `max_keepalive` option not applying to keepalive=0. Closes #2117. Thanks to David Nadlinger. --- ChangeLog.txt | 2 ++ src/handle_connect.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 54d5377a25..3d86cc588d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -22,6 +22,8 @@ Broker: - Fix bridge increasing backoff calculation. - Improve handling of invalid combinations of listener address and bind interface configurations. Closes #2081. +- Fix `max_keepalive` option not applying to clients connecting with keepalive + set to 0. Closes #2117. Client library: - Fix encrypted connections incorrectly connecting when the CA file passed to diff --git a/src/handle_connect.c b/src/handle_connect.c index 6dfd9e3ab3..c3355d90eb 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -244,7 +244,9 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1 goto error; } } - if(context->keepalive > db.config->max_keepalive){ + if(db.config->max_keepalive && + (context->keepalive > db.config->max_keepalive || context->keepalive == 0)){ + context->keepalive = db.config->max_keepalive; if(mosquitto_property_add_int16(&connack_props, MQTT_PROP_SERVER_KEEP_ALIVE, context->keepalive)){ rc = MOSQ_ERR_NOMEM;