Fix keep-alive disconnects on system time changes #3168
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
make test
with your changes locally?