From 2443f576ac9fa024306e9bfdc9a0f2d8dfb37e9b Mon Sep 17 00:00:00 2001
From: JKorf <jankorf91@gmail.com>
Date: Mon, 18 Sep 2023 20:02:01 +0200
Subject: [PATCH] Fix for concurrency exception

---
 CryptoExchange.Net/Sockets/SocketConnection.cs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs
index efb41cf..79964e8 100644
--- a/CryptoExchange.Net/Sockets/SocketConnection.cs
+++ b/CryptoExchange.Net/Sockets/SocketConnection.cs
@@ -291,7 +291,10 @@ namespace CryptoExchange.Net.Sockets
         /// <param name="requestId">Id of the request sent</param>
         protected virtual void HandleRequestSent(int requestId)
         {
-            var pendingRequest = _pendingRequests.SingleOrDefault(p => p.Id == requestId);
+            PendingRequest pendingRequest;
+            lock (_pendingRequests)
+                pendingRequest = _pendingRequests.SingleOrDefault(p => p.Id == requestId);
+
             if (pendingRequest == null)
             {
                 _logger.Log(LogLevel.Debug, $"Socket {SocketId} - msg {requestId} - message sent, but not pending");