From ba9ceed7cec0b12132f9e3e8a638b266134fefbb Mon Sep 17 00:00:00 2001 From: Johan x Lindqvist Date: Mon, 16 Sep 2019 11:33:37 +0200 Subject: [PATCH] Use Task.WhenAll to handle errors in both tasks. Previously if there was an exception in the first task that is awaited the second task would not be awaited. --- Source/MQTTnet/Client/MqttClient.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/MQTTnet/Client/MqttClient.cs b/Source/MQTTnet/Client/MqttClient.cs index 68045a2..c5224cb 100644 --- a/Source/MQTTnet/Client/MqttClient.cs +++ b/Source/MQTTnet/Client/MqttClient.cs @@ -269,8 +269,10 @@ namespace MQTTnet.Client await _adapter.DisconnectAsync(Options.CommunicationTimeout, CancellationToken.None).ConfigureAwait(false); } - await WaitForTaskAsync(_packetReceiverTask, sender).ConfigureAwait(false); - await WaitForTaskAsync(_keepAlivePacketsSenderTask, sender).ConfigureAwait(false); + var receiverTask = WaitForTaskAsync(_packetReceiverTask, sender); + var keepAliveTask = WaitForTaskAsync(_keepAlivePacketsSenderTask, sender); + + await Task.WhenAll(receiverTask, keepAliveTask).ConfigureAwait(false); _logger.Verbose("Disconnected from adapter."); }