eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.13k stars 2.41k forks source link

Fix keep-alive disconnects on system time changes #3168

Open karlri opened 3 days ago

karlri commented 3 days ago

Treat this as a request for comments for now. Potentially mosquitto_lib_init should be called instead and not just mosqutitto_time_init.

Calling mosqutitto_time_init seems to fix issues with changing system time back and forth one hour on Linux resulting in all clients with keep-alive being kicked instantly.

mosquitto_time_init must be called before calling mosquitto_time, otherwise time_clock will be 0 in mosquitto_time (per C99 standard initialized to 0 since there is no explicit init value) which will cause the realtime clock to be used when the intention seems to be to use the best monotonic clock supported by the platform.

That in turn causes the broker to kick clients when system time is changed because it's misinterpreted as clients failing on their keep-alive promises.

I need to check with my employer if I can sign the below referenced agreement.