eclipse / paho.mqtt.m2mqtt

Eclipse Public License 1.0
512 stars 303 forks source link

CPU Leak if you specify Username/password #66

Open malichishti opened 6 years ago

malichishti commented 6 years ago

Hi,

Im using M2MQTT from https://www.nuget.org/packages/M2Mqtt/ IF i create a client and specify a user name the CPU usgae goes up by 25% and stays there even if the connection fails due to wrong credentials. And next call to connect will increment the CPU usage by 25%

So if you have multiple thread connecting to MQTT server, after a couple of calls the CPU reached 100% and crashes. Following code can reproduce the issue, add it to a Console application .Net 4.5 or greater:


            Console.WriteLine("start?");
            Console.Read();
            Console.WriteLine("starting, please monitor the CPU usage.");
            List < MqttClient > l = new List<MqttClient>();
            for (int i = 0; i < 10; i++)
            {
                var client = new MqttClient(
                "test.mosquitto.org"
                , 1883
                , false
                , null
                , null
                , new MqttSslProtocols());
                client.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;
                try
                {
                    client.Connect(Guid.NewGuid().ToString(), "ss", null);//intentionally making it fail with wrong credentials
                }
                catch(Exception ex) { Console.WriteLine("Error");  }
                l.Add(client);
            }            

            Console.WriteLine("Exit?");
            Console.Read();```
ngducnghia commented 6 years ago

@malichishti I was able to fix my issue, lets me know if this fix yours.

vegaho commented 5 years ago

I have the same experience, not only the CPU is high. but also that the Process cannot be aborted, process must be kill force

rprediger commented 4 years ago

I have same problem.

jmillnik commented 3 years ago

Sad that this is still an issue in 2020.

pablocastilla commented 2 years ago

same problem here but using certificates