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

MqttClient.cs - Exception handling on SendReceive Exception #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jvcode1
Copy link

@jvcode1 jvcode1 commented Jun 22, 2016

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.

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;
Copy link

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

@vroyk
Copy link

vroyk commented Oct 10, 2016

This solves our problem. Please commit this change. Thanks!

@ppatierno
Copy link
Member

Hi,
can you give me an example on how reproduce the problem locally ?
In any case you don't have a valid signed Eclipse CLA you should sign (https://www.eclipse.org/legal/CLA.php)

@vroyk
Copy link

vroyk commented Jan 9, 2017

Hi,

It is very easy to reproduce:
I have a local ActiveMQ which I have configured for maximum 1 connection.
Now, I start two instances of my application.
The first application connects well, there is no problem.
The second application fails connecting. With each (re)try to connect, the CPU-use rises.
After a few tries, the CPU is 100%. It never recovers, unless we quit the application.

codami pushed a commit to codami/paho.mqtt.m2mqtt that referenced this pull request Jan 16, 2017
kejsi10 referenced this pull request Jun 21, 2017
fgabbaninililly added a commit to fgabbaninililly/PIDataReaderLib that referenced this pull request Oct 9, 2017
@kjschaef
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants