mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

MQTT 5.0 / Session Expiry Interval only works within one run of mosquitto

Open JSchy65 opened this issue 3 years ago • 1 comments

mosquitto broker version 1.6.15. (Oracle Linux 8)

MQTT 5.0 Specification chapter 3.1.2.11.2 Session Expiry Interval "Non-normative comment: The clock in the Client or Server may not be running for part of the time interval, for instance because the Client or Server are not running. This might cause the deletion of the state to be delayed."

As I understood the "Session Expiry Interval", it should be maintained even if the MQTT broker is not running. That means, if a subscriber sets the Session Expiry Interval to e.g. 30s and disconnects, the session should be removed even if the MQTT broker is down in meantime, probably in the next run of the MQTT broker.

Currently, it seems that mosquitto is not doing that.

Reproduction:

Probably remove mosquitto.db to have a clean start.

Start mosquitto with the following configuration: sys_interval 1 persistence true

Use subscribers to permanently check some values: mosquitto_sub -p 1883 -t '$SYS/broker/clients/connected' mosquitto_sub -p 1883 -t '$SYS/broker/clients/total'

what leads to:

clients/connected 2 clients/total 2

mosquitto_sub -p 1883 -q 1 -t test/# -c -i abc123 -D disconnect session-expiry-interval 30 -d

clients/connected 3 clients/total 3

stop subscriber / ctrl-c / -> disconnect

immediately start a stopwatch

clients/connected 2 clients/total 3

stop mosquitto broker / ctrl-c

wait some seconds

start mosquitto broker again

wait until > 30s are left since stop of subscriber

clients/connected 2 clients/total 3 !!!!! should be 2 ??

It's the same result with -q 2

Regardless how long you wait now, the subscriber will be not removed even the session-expiry-interval is passed.

My expectation is, that a session-expiry-interval is mantained even if the MQTT broker is stopped or powered off in meantime.

Probably similar issue like #2546 (persistent_client_expiration only works within one run of mosquitto) ?

Thank You very much, Regards Joachim Schachermayer

JSchy65 avatar Aug 10 '22 15:08 JSchy65

Thank you for the report and clear description of how to reproduce the problem. This issue has already been addressed in more recent versions of the broker, and I only intend to make security related fixes to the 1.6.x line of releases. Are you able to upgrade to 2.0.14?

ralight avatar Aug 11 '22 10:08 ralight

I tested now with Mosquitto 2.0.14 on Ubuntu 20.04.3 LTS. There is the same behaviour as described above.

On Oracle Linux 8 there is only mosquitto 1.6.15 available. But we check if we can upgrade to 2.0.14.

JSchy65 avatar Aug 12 '22 10:08 JSchy65

My apologies, I may have been testing against the fixes branch which does contain a relevant change for this, rather than against 2.0.14. I am planning the 2.0.15 release for Monday which will include this.

If this is important for your company, maybe I could suggest that the company I work for, Cedalo, may be able to help - perhaps by making Oracle compatible packages for 2.0.15, or some other solution: https://cedalo.com/contact-us/

ralight avatar Aug 12 '22 11:08 ralight

In meantime I retested with 2.0.15 and it behaved as expected -> issue is fixed.

Thank you very much for your support.

JSchy65 avatar Aug 17 '22 12:08 JSchy65