MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.5k
stars
1.07k
forks
source link
MqttNet Connection not established after the Mqttnet Client is Disposed. in MQTTNet Version 4.3.3.952 #2072
Before opening a bug make sure that the following conditions are met.
Performance issues are also appearing in RELEASE mode of your application.
An increased memory consumption or high CPU load also happens when your application runs in RELEASE mode AND logging is DISABLED.
Client issues with not received messages, connection drops etc. can be reproduced via another client application like "MQTTnetApp" (https://github.com/chkr1011/MQTTnetApp) or similar.
The bug also appears in the VERY LATEST version of this library. There is no support for older version (due to limited resources) but pull requests for older versions are welcome.
Describe the bug
A clear and concise description of what the bug is.
When ever we are disposing the MQTT NET client upon reconnecting the MqttClientConnectedHandler is not getting hit.
public void Dispose()
{
try
{
Logger.Info("Dispose() | Cloud connector disposing ...");
DisconnectClient().Wait();
Logger.Error("Dispose() | Cloud connector disposed");
}
catch (Exception ex)
{
Logger.Fatal($"Dispose() | Failed to dispose cloud connector {ex}");
}
}
A job which runs every 2 minutes hits again we are getting the following exception
Exception: System.InvalidOperationException: It is not allowed to connect with a server after the connection is established.
at MQTTnet.Client.MqttClient.d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Which component is your bug related to?
Client
To Reproduce
Steps to reproduce the behavior:
Using this version of MQTTnet '4.3.3.952'.
Run this code '....'.
With these arguments '....'.
See error.
Expected behavior
A clear and concise description of what you expected to happen.
upon disposing the client and retrying to connect the client should connect and the handler should hit.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context / logging
Add any other context about the problem here.
Include debugging or logging information here:
\\ Put your logging output here.
Code example
Please provide full code examples below where possible to make it easier for the developers to check your issues.
Ideally a Unit Test (which shows the error) is provided so that the behavior can be reproduced easily.
Verification
Before opening a bug make sure that the following conditions are met.
Describe the bug
A clear and concise description of what the bug is. When ever we are disposing the MQTT NET client upon reconnecting the MqttClientConnectedHandler is not getting hit.
public void Dispose() { try { Logger.Info("Dispose() | Cloud connector disposing ..."); DisconnectClient().Wait(); Logger.Error("Dispose() | Cloud connector disposed"); } catch (Exception ex) { Logger.Fatal($"Dispose() | Failed to dispose cloud connector {ex}"); } } A job which runs every 2 minutes hits again we are getting the following exception
Exception: System.InvalidOperationException: It is not allowed to connect with a server after the connection is established. at MQTTnet.Client.MqttClient.d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Which component is your bug related to?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen. upon disposing the client and retrying to connect the client should connect and the handler should hit.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context / logging
Add any other context about the problem here. Include debugging or logging information here:
Code example
Please provide full code examples below where possible to make it easier for the developers to check your issues.
Ideally a Unit Test (which shows the error) is provided so that the behavior can be reproduced easily.