-
Notifications
You must be signed in to change notification settings - Fork 304
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
MqttClient.cs - Exception handling on SendReceive Exception #6
base: master
Are you sure you want to change the base?
Conversation
In case that the broker terminates the connection "SendReceive" throws a MqttCommunicationException, therefore the Connect-method is exited and "this.isRunning" remains true. Hence the threads are not terminated properly and keep hanging and consuming resources on error. Example exception when HiveMQ closes the connection (e.g. when too less licenses are available): uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException: Eine Ausnahme vom Typ "uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException" wurde ausgelöst. bei uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 1094. bei uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(MqttMsgBase msg, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 1117. bei uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 567. bei uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 494.
catch (MqttCommunicationException e) | ||
{ | ||
this.isRunning = false; | ||
throw e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to just throw;
which preserves the original stack trace
This solves our problem. Please commit this change. Thanks! |
Hi, |
Hi, It is very easy to reproduce: |
@ppatierno This bug bit me in production and caused some major problems by taking down an important PC. It appears that this project has been abandoned, but there are about 10 PR's calling out exactly this same issue. It would be a great service to the community if you could accept one of them and save others from finding it the hard way. Thanks! |
In case that the broker terminates the connection "SendReceive" throws a MqttCommunicationException, therefore the Connect-method is exited and "this.isRunning" remains true. Hence the threads are not terminated properly and keep hanging and consuming resources on error.
Example exception when HiveMQ closes the connection (e.g. when too less licenses are available):
uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException: Eine Ausnahme vom Typ "uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException" wurde ausgelöst.
bei uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 1094.
bei uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(MqttMsgBase msg, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 1117.
bei uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 567.
bei uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:Zeile 494.