Connection timeout when system time is set to a time in the past
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
A connection timeout occurs when the system time is set to a time in the past.
### Which component is your bug related to?
- Client
### To Reproduce
Steps to reproduce the behavior:
1. Using this version of MQTTnet '5.0.0.1214-RC'.
3. Run the following code on Ubuntu 22.04.5 LTS.
Adjust the host and credentials to match your MQTT broker (I only tested with a mosquitto MQTT broker running on another machine).
```csharp
using MQTTnet;
var factory = new MqttClientFactory();
using var client = factory.CreateMqttClient();
var options = new MqttClientOptionsBuilder()
.WithTcpServer("192.168.0.10")
.WithCredentials("mosquitto", "mosquitto")
.Build();
client.ConnectingAsync += _ =>
{
Console.WriteLine("Connecting");
return Task.CompletedTask;
};
client.ConnectedAsync += _ =>
{
Console.WriteLine("Connected");
return Task.CompletedTask;
};
client.DisconnectedAsync += _ =>
{
Console.WriteLine("Disconnected");
return Task.CompletedTask;
};
await client.ConnectAsync(options);
while (true)
{
}
```
6. The application prints `Connecting` and `Connected` as expected.
7. Change the system time to a time in the past, e.g., calling `sudo timedatectl set-time '2024-12-12 04:00:00'`
9. Wait for 30 s
10. The program prints `Disconnected`
11. The mosquitto MQTT broker prints `Client ... has exceeded timeout, disconnecting`
### Additional context / logging
Setting the system time to a time in the future seems to be no problem.
This issue does not occur with mosquitto_sub. Tested with
```batch
mosquitto_sub -h 192.168.0.10 -t \# -u mosquitto -P mosquitto
```
When the MQTTnet client disconnects, the mosquitto_sub application remains running and outputs received messages and the MQTT broker prints only the timeout information for the MQTTnet client and not for the mosquitto_sub.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.