diff --git a/MQTTnet.Core/Client/MqttClient.cs b/MQTTnet.Core/Client/MqttClient.cs index 799da52..8be6450 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/MQTTnet.Core/Client/MqttClient.cs @@ -352,6 +352,11 @@ namespace MQTTnet.Core.Client } 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 @@ namespace MQTTnet.Core.Client } catch (MqttCommunicationException exception) { + if (cancellationToken.IsCancellationRequested) + { + return; + } + MqttTrace.Warning(nameof(MqttClient), exception, "MQTT communication exception while receiving packets."); await DisconnectInternalAsync().ConfigureAwait(false); }