From 1d4353e6d1e0fdda0700e6e69f2e1419be073539 Mon Sep 17 00:00:00 2001 From: JKorf Date: Fri, 14 Apr 2023 21:02:21 +0200 Subject: [PATCH] Fixed potential collection modified exception --- CryptoExchange.Net/Sockets/SocketConnection.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs index 2964fbf..20bef25 100644 --- a/CryptoExchange.Net/Sockets/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/SocketConnection.cs @@ -629,7 +629,11 @@ namespace CryptoExchange.Net.Sockets return new CallResult(true); } - if (_subscriptions.Any(s => s.Authenticated)) + bool anyAuthenticated = false; + lock (_subscriptionLock) + anyAuthenticated = _subscriptions.Any(s => s.Authenticated); + + if (anyAuthenticated) { // If we reconnected a authenticated connection we need to re-authenticate var authResult = await ApiClient.AuthenticateSocketAsync(this).ConfigureAwait(false);