mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-18 13:26:26 +00:00
Dont lock subscriptions during message handling
This commit is contained in:
parent
29ebd13958
commit
89de0da724
@ -1030,6 +1030,13 @@
|
||||
<param name="cancellationToken"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.ExtensionMethods.WaitOneAsync(System.Threading.WaitHandle)">
|
||||
<summary>
|
||||
Wait one async
|
||||
</summary>
|
||||
<param name="handle"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.ExtensionMethods.WaitOneAsync(System.Threading.WaitHandle,System.TimeSpan)">
|
||||
<summary>
|
||||
Wait one async
|
||||
|
@ -224,31 +224,32 @@ namespace CryptoExchange.Net.Sockets
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
// Loop the subscriptions to check if any of them signal us that the message is for them
|
||||
List<SocketSubscription> subscriptionsCopy;
|
||||
lock (subscriptionLock)
|
||||
subscriptionsCopy = subscriptions.ToList();
|
||||
|
||||
foreach (var subscription in subscriptionsCopy)
|
||||
{
|
||||
foreach (var subscription in subscriptions.ToList())
|
||||
currentSubscription = subscription;
|
||||
if (subscription.Request == null)
|
||||
{
|
||||
currentSubscription = subscription;
|
||||
if (subscription.Request == null)
|
||||
if (socketClient.MessageMatchesHandler(messageEvent.JsonData, subscription.Identifier!))
|
||||
{
|
||||
if (socketClient.MessageMatchesHandler(messageEvent.JsonData, subscription.Identifier!))
|
||||
{
|
||||
handled = true;
|
||||
subscription.MessageHandler(messageEvent);
|
||||
}
|
||||
handled = true;
|
||||
subscription.MessageHandler(messageEvent);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (socketClient.MessageMatchesHandler(messageEvent.JsonData, subscription.Request))
|
||||
{
|
||||
if (socketClient.MessageMatchesHandler(messageEvent.JsonData, subscription.Request))
|
||||
{
|
||||
handled = true;
|
||||
messageEvent.JsonData = socketClient.ProcessTokenData(messageEvent.JsonData);
|
||||
subscription.MessageHandler(messageEvent);
|
||||
}
|
||||
handled = true;
|
||||
messageEvent.JsonData = socketClient.ProcessTokenData(messageEvent.JsonData);
|
||||
subscription.MessageHandler(messageEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sw.Stop();
|
||||
if (sw.ElapsedMilliseconds > 500)
|
||||
log.Write(LogLevel.Warning, $"Socket {Socket.Id} message processing slow ({sw.ElapsedMilliseconds}ms), consider offloading data handling to another thread. " +
|
||||
|
Loading…
x
Reference in New Issue
Block a user