dotnet / dotnet/MQTTnet

Client disconnects every 4 hours

Open
#1,733 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

### Describe your question
I have a C# console application in which a Mqtt client sends data to a server. The application is running with Docker on a remote PC with Ubuntu 22.04, SIM card and GSM module. In normal circumstances everything works fine but every 4 hours the event IMqttClient.DisconnectedAysnc is fired and I cannot understand why. When it happens, I try to ping google.com and the command is always successful, so I don't think it is a connection issue.
I have the same app running on a PC with the same specs and settings but with cabled connection to internet and is not suffering from this problem.
I don't know if this is related to the MQTTnet package or not.
Event handler function:

```
private async Task MqttClient_DisconnectedAsync(MqttClientDisconnectedEventArgs arg)
{
try
{
_logger.Warning($"Mqtt client disconnected, reason: {arg.Reason}, ex: {arg.Exception?.Message}");
Ping();
await Connect();
}
catch (Exception ex)
{
_logger.Error(ex, "Mqtt client disconnected, reconnect failed.");
}
}
```

Some logs:
```
2023-05-08 11:08:28.692 +00:00 [WRN] Mqtt client disconnected, reason: NormalDisconnection, ex: The operation has timed out.
2023-05-08 15:08:08.957 +00:00 [WRN] Mqtt client disconnected, reason: NormalDisconnection, ex: The operation has timed out.
2023-05-08 19:08:05.591 +00:00 [WRN] Mqtt client disconnected, reason: NormalDisconnection, ex: The operation has timed out.
2023-05-08 23:08:08.776 +00:00 [WRN] Mqtt client disconnected, reason: NormalDisconnection, ex: The operation has timed out.
```
Has anyone had this problem before?

Any help is really appreciated
Thanks,
Alessandro

### Which project is your question related to?

- Client

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.