eclipse / paho.mqtt.m2mqtt

Eclipse Public License 1.0
512 stars 303 forks source link

Multiple socket opened when authentication fails #62

Open robertsLando opened 6 years ago

robertsLando commented 6 years ago

Sockets are not closed if authentication fails, after some tries application stop responding and must be closed. In the image below there are the threads created after 3 failed auth:

immagine

s4v4g3 commented 6 years ago

I see the same problem & looks like the fix is easy, just add an "else" case in the Connect() method:

if (connack.ReturnCode == MqttMsgConnack.CONN_ACCEPTED)
{
       // ......
}
else
{
      Close();
}
robertsLando commented 6 years ago

@s4v4g3 How can I fix this in my application as I can't edit the library reference code? It would be easy to add at line 602 of MqttClient.cs

else
{
      Close();
}
s4v4g3 commented 6 years ago

I made a local build of the .NET 4.5 library that you can try out if you like. https://www.dropbox.com/s/cjk89lyi2s85d00/M2Mqtt.Net.dll?dl=0

robertsLando commented 6 years ago

Thanks very much @s4v4g3! Just downloaded the source code of M2MQTT, added those lines to MqttCLient.cs, recompiled the project to make the dll and added a reference to it in my project. Now sockets are closed correctly if auth goes wrong! I have make a PR (#64)