From f76e13028316e3d1757d871bb9f200945a72583d Mon Sep 17 00:00:00 2001 From: vbBerni Date: Wed, 19 Jun 2019 16:33:54 +0200 Subject: [PATCH 1/2] fix for failed publishing messages get removed from the message queue but not from the storage manager --- Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs index 59f1c9a..b27bead 100644 --- a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs +++ b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs @@ -408,6 +408,7 @@ namespace MQTTnet.Extensions.ManagedClient { _messageQueue.RemoveFirst(i => i.Id.Equals(message.Id)); } + _storageManager?.RemoveAsync(message).GetAwaiter().GetResult(); } } catch (Exception exception) From a9017b87959f60d9070cea4a9d8bed9de3a7088d Mon Sep 17 00:00:00 2001 From: vbBerni Date: Sat, 22 Jun 2019 22:31:48 +0200 Subject: [PATCH 2/2] handle storage manager null --- .../ManagedMqttClient.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs index b27bead..dc57e40 100644 --- a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs +++ b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs @@ -387,7 +387,10 @@ namespace MQTTnet.Extensions.ManagedClient //removed it, in which case we don't want to do anything. _messageQueue.RemoveFirst(i => i.Id.Equals(message.Id)); } - _storageManager?.RemoveAsync(message).GetAwaiter().GetResult(); + if (_storageManager != null) + { + _storageManager.RemoveAsync(message).GetAwaiter().GetResult(); + } } catch (MqttCommunicationException exception) { @@ -408,7 +411,10 @@ namespace MQTTnet.Extensions.ManagedClient { _messageQueue.RemoveFirst(i => i.Id.Equals(message.Id)); } - _storageManager?.RemoveAsync(message).GetAwaiter().GetResult(); + if (_storageManager != null) + { + _storageManager.RemoveAsync(message).GetAwaiter().GetResult(); + } } } catch (Exception exception)