Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection timeout when system time is set to a time in the past #2128

Open
andreasgrosche opened this issue Dec 16, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@andreasgrosche
Copy link

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'.
  2. 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).
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)
{
}
  1. The application prints Connecting and Connected as expected.
  2. Change the system time to a time in the past, e.g., calling sudo timedatectl set-time '2024-12-12 04:00:00'
  3. Wait for 30 s
  4. The program prints Disconnected
  5. 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

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.

@andreasgrosche andreasgrosche added the bug Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant