eclipse / mosquitto

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

MQTT clients got disconnected after manual date time change using "date -s" #2205

Open mob-lesu opened 3 years ago

mob-lesu commented 3 years ago

Environment: Linux in embedded project, Mosquitto 1.6.12 Test steps:

  1. Execute command with some time and date: date -s "2021-01-01 01:01"
  2. Check logs in journalctl
    Jan 01 01:01:24 SXXX mosquitto[3693]: 1609462884: Client MQTT client x_service has exceeded timeout, disconnecting.
    Jan 01 01:01:24 SXXX mosquitto[3693]: 1609462884: Client MQTT client y_service has exceeded timeout, disconnecting.
    Jan 01 01:01:24 SXXX mosquitto[3693]: 1609462884: Client MQTT client z_service has exceeded timeout, disconnecting.

    Current behavior: Several client services are disconnected and then reconnected.

Expected: No disconnection occurs.

This might be related to:

/* Client has exceeded keepalive*1.5 */
do_disconnect(db, context, MOSQ_ERR_KEEPALIVE)

Thanks in advance for Your help.

ralight commented 3 years ago

It sounds like your embedded platform does not define _POSIX_MONOTONIC_CLOCK, so mosquitto is unable use clock_gettime(CLOCK_MONOTONIC, &tp) to get the current time, and must use time(NULL) instead. The output of CLOCK_MONOTONIC does not change when date -s .... is used, but the output of time(NULL) does.

This does seem unlikely though, musl c has supported them for years for example. What platform are you using, and can you confirm it does support CLOCK_MONOTONIC?