mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
Fixed websocket client trying to unsubscribe subscription when the connection will be closed anyway
This commit is contained in:
parent
949780a9ad
commit
776d75170d
@ -590,12 +590,16 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
bool anyDuplicateSubscription;
|
bool anyDuplicateSubscription;
|
||||||
lock (_listenersLock)
|
lock (_listenersLock)
|
||||||
anyDuplicateSubscription = _listeners.OfType<Subscription>().Any(x => x != subscription && x.ListenerIdentifiers.All(l => subscription.ListenerIdentifiers.Contains(l)));
|
anyDuplicateSubscription = _listeners.OfType<Subscription>().Any(x => x != subscription && x.ListenerIdentifiers.All(l => subscription.ListenerIdentifiers.Contains(l)));
|
||||||
|
|
||||||
|
bool shouldCloseConnection;
|
||||||
|
lock (_listenersLock)
|
||||||
|
shouldCloseConnection = _listeners.OfType<Subscription>().All(r => !r.UserSubscription || r.Closed) && !DedicatedRequestConnection;
|
||||||
|
|
||||||
if (!anyDuplicateSubscription)
|
if (!anyDuplicateSubscription)
|
||||||
{
|
{
|
||||||
bool needUnsub;
|
bool needUnsub;
|
||||||
lock (_listenersLock)
|
lock (_listenersLock)
|
||||||
needUnsub = _listeners.Contains(subscription);
|
needUnsub = _listeners.Contains(subscription) && !shouldCloseConnection;
|
||||||
|
|
||||||
if (needUnsub && _socket.IsOpen)
|
if (needUnsub && _socket.IsOpen)
|
||||||
await UnsubscribeAsync(subscription).ConfigureAwait(false);
|
await UnsubscribeAsync(subscription).ConfigureAwait(false);
|
||||||
@ -611,16 +615,9 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldCloseConnection;
|
|
||||||
lock (_listenersLock)
|
|
||||||
{
|
|
||||||
shouldCloseConnection = _listeners.OfType<Subscription>().All(r => !r.UserSubscription || r.Closed) && !DedicatedRequestConnection;
|
|
||||||
if (shouldCloseConnection)
|
|
||||||
Status = SocketStatus.Closing;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldCloseConnection)
|
if (shouldCloseConnection)
|
||||||
{
|
{
|
||||||
|
Status = SocketStatus.Closing;
|
||||||
_logger.ClosingNoMoreSubscriptions(SocketId);
|
_logger.ClosingNoMoreSubscriptions(SocketId);
|
||||||
await CloseAsync().ConfigureAwait(false);
|
await CloseAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user