MQTT needs better error handling when It can't find the server. It always crashes the application

Hi All,

When I use VL.MQTT 1.2.5 its nice until the broker disconnects, then I get this error with no obvious way to handle it to prevent crashing the application. I’ve tried wrapping the client node in a Try but that doesn’t work.

SocketException: "A socket operation was attempted to an unreachable host."
    StackTrace:
        System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs { private void ThrowException(System.Net.Sockets.SocketError error, System.Threading.CancellationToken cancellationToken) { ... } } 
        System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs { private virtual void System.Threading.Tasks.Sources.IValueTaskSource.GetResult(short token) { ... } } 
        System.Net.Sockets.Socket+<<ConnectAsync>g__WaitForConnectWithCancellation|285_0>d { private virtual void MoveNext() { ... } } 
        System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { ... } } 
        System.Runtime.CompilerServices.TaskAwaiter { private static void ThrowForNonSuccess(System.Threading.Tasks.Task task) { ... } } 
        System.Runtime.CompilerServices.TaskAwaiter { private static void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task, System.Threading.Tasks.ConfigureAwaitOptions options) { ... } } 
        MQTTnet.Implementations.CrossPlatformSocket+<ConnectAsync>d__46 { private virtual void MoveNext() { ... } } 

MqttCommunicationException: “Error while connecting host ‘Unspecified/192.168.1.38:1883’.”
StackTrace:
MQTTnet.Implementations.CrossPlatformSocket+d__46 { private virtual void MoveNext() { … } }
System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void ThrowForNonSuccess(System.Threading.Tasks.Task task) { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task, System.Threading.Tasks.ConfigureAwaitOptions options) { … } }
MQTTnet.Implementations.MqttTcpChannel+d__16 { private virtual void MoveNext() { … } }
System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void ThrowForNonSuccess(System.Threading.Tasks.Task task) { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task, System.Threading.Tasks.ConfigureAwaitOptions options) { … } }
MQTTnet.Adapter.MqttChannelAdapter+<>c__DisplayClass30_0+<b__1>d { private virtual void MoveNext() { … } }
System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void ThrowForNonSuccess(System.Threading.Tasks.Task task) { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task, System.Threading.Tasks.ConfigureAwaitOptions options) { … } }
MQTTnet.Adapter.MqttChannelAdapter+d__30 { private virtual void MoveNext() { … } }
System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void ThrowForNonSuccess(System.Threading.Tasks.Task task) { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task, System.Threading.Tasks.ConfigureAwaitOptions options) { … } }
MQTTnet.MqttClient+d__55 { private virtual void MoveNext() { … } }
System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void ThrowForNonSuccess(System.Threading.Tasks.Task task) { … } }
System.Runtime.CompilerServices.TaskAwaiter { private static void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task, System.Threading.Tasks.ConfigureAwaitOptions options) { … } }
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter { public TResult GetResult() { … } }
MQTTnet.MqttClient+d__42 { private virtual void MoveNext() { … } }
System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { … } }
MQTTnet.MqttClient+d__42 { private virtual void MoveNext() { … } }
System.Runtime.ExceptionServices.ExceptionDispatchInfo { public void Throw() { … } }
VL.Lang.Platforms.RuntimeHost { protected virtual void Step() { … } }

Think thats related: