From 6c8f85afe9dc614c1d3aa02f2e935c0549182ddc Mon Sep 17 00:00:00 2001 From: JanEggers Date: Sat, 9 Sep 2017 02:48:13 +0200 Subject: [PATCH 1/3] fixed invalid operation exception --- MQTTnet.Core/Client/MqttPacketDispatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MQTTnet.Core/Client/MqttPacketDispatcher.cs b/MQTTnet.Core/Client/MqttPacketDispatcher.cs index 0784e8a..befca59 100644 --- a/MQTTnet.Core/Client/MqttPacketDispatcher.cs +++ b/MQTTnet.Core/Client/MqttPacketDispatcher.cs @@ -41,7 +41,7 @@ namespace MQTTnet.Core.Client { if (packetAwaiter.PacketSelector(packet)) { - packetAwaiter.SetResult(packet); + packetAwaiter.TrySetResult(packet); packetDispatched = true; break; } From 861efa5e75ba715c2fc6158b82b294b8149f01a5 Mon Sep 17 00:00:00 2001 From: JanEggers Date: Sat, 9 Sep 2017 08:14:53 +0200 Subject: [PATCH 2/3] dont add the same package twice to _receivedPackets --- MQTTnet.Core/Client/MqttPacketDispatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MQTTnet.Core/Client/MqttPacketDispatcher.cs b/MQTTnet.Core/Client/MqttPacketDispatcher.cs index befca59..da8b1fa 100644 --- a/MQTTnet.Core/Client/MqttPacketDispatcher.cs +++ b/MQTTnet.Core/Client/MqttPacketDispatcher.cs @@ -10,7 +10,7 @@ namespace MQTTnet.Core.Client public class MqttPacketDispatcher { private readonly object _syncRoot = new object(); - private readonly List _receivedPackets = new List(); + private readonly HashSet _receivedPackets = new HashSet(); private readonly List _packetAwaiters = new List(); public async Task WaitForPacketAsync(Func selector, TimeSpan timeout) From 80a6e6809cf4ba56394a6fe20b9078d73ae78215 Mon Sep 17 00:00:00 2001 From: JanEggers Date: Sun, 10 Sep 2017 12:16:44 +0200 Subject: [PATCH 3/3] use same lockobject everywhere to prevent raceconditions --- MQTTnet.Core/Client/MqttPacketDispatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MQTTnet.Core/Client/MqttPacketDispatcher.cs b/MQTTnet.Core/Client/MqttPacketDispatcher.cs index da8b1fa..aba050d 100644 --- a/MQTTnet.Core/Client/MqttPacketDispatcher.cs +++ b/MQTTnet.Core/Client/MqttPacketDispatcher.cs @@ -71,7 +71,7 @@ namespace MQTTnet.Core.Client private List GetPacketAwaiters() { - lock (_packetAwaiters) + lock (_syncRoot) { return new List(_packetAwaiters); }