From 50800b1d441710fe359ccaa0bb84146b50e9c4bb Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Wed, 20 Sep 2017 21:36:32 +0200 Subject: [PATCH] Fix issues with exception handling after disconnect --- MQTTnet.Core/Client/MqttClient.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MQTTnet.Core/Client/MqttClient.cs b/MQTTnet.Core/Client/MqttClient.cs index 799da5242..8be6450ee 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/MQTTnet.Core/Client/MqttClient.cs @@ -352,6 +352,11 @@ private async Task SendKeepAliveMessagesAsync(CancellationToken cancellationToke } catch (MqttCommunicationException exception) { + if (cancellationToken.IsCancellationRequested) + { + return; + } + MqttTrace.Warning(nameof(MqttClient), exception, "MQTT communication exception while sending/receiving keep alive packets."); await DisconnectInternalAsync().ConfigureAwait(false); } @@ -388,6 +393,11 @@ private async Task ReceivePackets(CancellationToken cancellationToken) } catch (MqttCommunicationException exception) { + if (cancellationToken.IsCancellationRequested) + { + return; + } + MqttTrace.Warning(nameof(MqttClient), exception, "MQTT communication exception while receiving packets."); await DisconnectInternalAsync().ConfigureAwait(false); }