mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 08:26:20 +00:00
Immediate initial reconnect attempt when connection is lost
This commit is contained in:
parent
6eb43c5218
commit
0268e211e9
@ -377,7 +377,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
Socket.Reconnecting = true;
|
Socket.Reconnecting = true;
|
||||||
|
|
||||||
DisconnectTime = DateTime.UtcNow;
|
DisconnectTime = DateTime.UtcNow;
|
||||||
log.Write(LogLevel.Information, $"Socket {Socket.Id} Connection lost, will try to reconnect after {socketClient.ClientOptions.ReconnectInterval}");
|
log.Write(LogLevel.Information, $"Socket {Socket.Id} Connection lost, will try to reconnect{(ReconnectTry == 0 ? "": $" after {socketClient.ClientOptions.ReconnectInterval}")}");
|
||||||
if (!lostTriggered)
|
if (!lostTriggered)
|
||||||
{
|
{
|
||||||
lostTriggered = true;
|
lostTriggered = true;
|
||||||
@ -387,9 +387,13 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
while (ShouldReconnect)
|
while (ShouldReconnect)
|
||||||
|
{
|
||||||
|
if (ReconnectTry > 0)
|
||||||
{
|
{
|
||||||
// Wait a bit before attempting reconnect
|
// Wait a bit before attempting reconnect
|
||||||
await Task.Delay(socketClient.ClientOptions.ReconnectInterval).ConfigureAwait(false);
|
await Task.Delay(socketClient.ClientOptions.ReconnectInterval).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (!ShouldReconnect)
|
if (!ShouldReconnect)
|
||||||
{
|
{
|
||||||
// Should reconnect changed to false while waiting to reconnect
|
// Should reconnect changed to false while waiting to reconnect
|
||||||
@ -416,7 +420,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Write(LogLevel.Debug, $"Socket {Socket.Id} failed to reconnect{(socketClient.ClientOptions.MaxReconnectTries != null ? $", try {ReconnectTry}/{socketClient.ClientOptions.MaxReconnectTries}": "")}");
|
log.Write(LogLevel.Debug, $"Socket {Socket.Id} failed to reconnect{(socketClient.ClientOptions.MaxReconnectTries != null ? $", try {ReconnectTry}/{socketClient.ClientOptions.MaxReconnectTries}": "")}, will try again in {socketClient.ClientOptions.ReconnectInterval}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user