1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-08 00:16:27 +00:00

Fix for Message not handled when closing subscription, fix for reconnect loop

This commit is contained in:
JKorf 2022-07-12 22:06:38 +02:00
parent 41f17d0378
commit c815fad135
3 changed files with 11 additions and 3 deletions

View File

@ -250,7 +250,7 @@ namespace CryptoExchange.Net.Sockets
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task ReconnectAsync() public virtual async Task ReconnectAsync()
{ {
if (_processState != ProcessState.Processing) if (_processState != ProcessState.Processing && IsOpen)
return; return;
_log.Write(LogLevel.Debug, $"Socket {Id} reconnect requested"); _log.Write(LogLevel.Debug, $"Socket {Id} reconnect requested");

View File

@ -385,7 +385,7 @@ namespace CryptoExchange.Net.Sockets
if (!subscriptions.Contains(subscription)) if (!subscriptions.Contains(subscription))
return; return;
subscriptions.Remove(subscription); subscription.Closed = true;
} }
if (Status == SocketStatus.Closing || Status == SocketStatus.Closed || Status == SocketStatus.Disposed) if (Status == SocketStatus.Closing || Status == SocketStatus.Closed || Status == SocketStatus.Disposed)
@ -407,7 +407,7 @@ namespace CryptoExchange.Net.Sockets
return; return;
} }
shouldCloseConnection = subscriptions.All(r => !r.UserSubscription); shouldCloseConnection = subscriptions.All(r => !r.UserSubscription || r.Closed);
if (shouldCloseConnection) if (shouldCloseConnection)
Status = SocketStatus.Closing; Status = SocketStatus.Closing;
} }
@ -417,6 +417,9 @@ namespace CryptoExchange.Net.Sockets
log.Write(LogLevel.Debug, $"Socket {SocketId} closing as there are no more subscriptions"); log.Write(LogLevel.Debug, $"Socket {SocketId} closing as there are no more subscriptions");
await CloseAsync().ConfigureAwait(false); await CloseAsync().ConfigureAwait(false);
} }
lock (subscriptionLock)
subscriptions.Remove(subscription);
} }
/// <summary> /// <summary>

View File

@ -48,6 +48,11 @@ namespace CryptoExchange.Net.Sockets
/// </summary> /// </summary>
public bool Authenticated { get; set; } public bool Authenticated { get; set; }
/// <summary>
/// Whether we're closing this subscription and a socket connection shouldn't be kept open for it
/// </summary>
public bool Closed { get; set; }
/// <summary> /// <summary>
/// Cancellation token registration, should be disposed when subscription is closed. Used for closing the subscription with /// Cancellation token registration, should be disposed when subscription is closed. Used for closing the subscription with
/// a provided cancelation token /// a provided cancelation token