eclipse/paho.mqtt.m2mqtt

Inflight thread in .NET MqttClient crashes (and the whole application) if exception is thrown inside the thread

dmitrybg opened this issue · 0 comments

The following code makes application crash. Problem is that when MqttMsgPublish.GetBytes() function makes check for wildcards inside the topic name while publishing message, it (reasonably) throws exception MqttClientException(MqttClientErrorCode.TopicWildcard) (line 107 of the file MqttMsgPublish.cs). This exception is NOT handled anywhere in inflight threads and makes the whole app crashing. I suggest to move this and other related checks from GetBytes() function to MqttClient.Publish() function or make some notification mechanism for errors in inflight thread.

static void Main(string[] args)
        {
            MqttClient mqtt = new MqttClient("servername");
            mqtt.Connect(Guid.NewGuid().ToString());
            string topic = "/h1/+"; // <--- INVALID TOPIC HERE (wildcards)
            mqtt.Publish(topic, Encoding.UTF8.GetBytes("Hello".ToCharArray()));

            Console.ReadLine();
        }