mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-09 17:06:19 +00:00
Protect pendingRequest list from concurrent access.
This commit is contained in:
parent
9deae358ac
commit
0db71a3fb6
@ -148,11 +148,19 @@ namespace CryptoExchange.Net.Sockets
|
||||
}
|
||||
|
||||
var handledResponse = false;
|
||||
foreach (var pendingRequest in pendingRequests.ToList())
|
||||
PendingRequest[] requests;
|
||||
lock(pendingRequests)
|
||||
{
|
||||
requests = pendingRequests.ToArray();
|
||||
}
|
||||
foreach (var pendingRequest in requests)
|
||||
{
|
||||
if (pendingRequest.Check(tokenData))
|
||||
{
|
||||
pendingRequests.Remove(pendingRequest);
|
||||
lock (pendingRequests)
|
||||
{
|
||||
pendingRequests.Remove(pendingRequest);
|
||||
}
|
||||
if (pendingRequest.Result == null)
|
||||
{
|
||||
continue; // A previous timeout.
|
||||
@ -237,7 +245,10 @@ namespace CryptoExchange.Net.Sockets
|
||||
public virtual Task SendAndWait<T>(T obj, TimeSpan timeout, Func<JToken, bool> handler)
|
||||
{
|
||||
var pending = new PendingRequest(handler, timeout);
|
||||
pendingRequests.Add(pending);
|
||||
lock (pendingRequests)
|
||||
{
|
||||
pendingRequests.Add(pending);
|
||||
}
|
||||
Send(obj);
|
||||
return pending.Event.WaitOneAsync(timeout);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user