From 93a64b2b1d1861ba6182367b8fc0371c2ff3094d Mon Sep 17 00:00:00 2001 From: Jan Korf Date: Tue, 27 Apr 2021 15:34:33 +0200 Subject: [PATCH] Fixed unhandled messages after unsubscribing --- CryptoExchange.Net/Sockets/SocketConnection.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs index 9dcc38b..696d787 100644 --- a/CryptoExchange.Net/Sockets/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/SocketConnection.cs @@ -424,14 +424,13 @@ namespace CryptoExchange.Net.Sockets var shouldCloseWrapper = false; lock (handlersLock) - { - handlers.Remove(subscription); - if (handlers.Count(r => r.UserSubscription) == 0) - shouldCloseWrapper = true; - } + shouldCloseWrapper = handlers.Count(r => r.UserSubscription && subscription != r) == 0; if (shouldCloseWrapper) await Close().ConfigureAwait(false); + + lock (handlersLock) + handlers.Remove(subscription); } }