1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-10 17:36:19 +00:00

Updated revitalize request signature, added exception handler reconnect logic

This commit is contained in:
JKorf 2024-02-21 19:39:31 +01:00
parent 68e525ab9d
commit f917bf0e3f
2 changed files with 25 additions and 17 deletions

View File

@ -424,13 +424,13 @@ namespace CryptoExchange.Net
}
/// <summary>
/// Update the original request to send when the connection is restored after disconnecting. Can be used to update an authentication token for example.
/// Update the subscription when the connection is restored after disconnecting. Can be used to update an authentication token for example.
/// </summary>
/// <param name="request">The original request</param>
/// <param name="subscription">The subscription</param>
/// <returns></returns>
protected internal virtual Task<CallResult<object>> RevitalizeRequestAsync(object request)
protected internal virtual Task<CallResult> RevitalizeRequestAsync(Subscription subscription)
{
return Task.FromResult(new CallResult<object>(request));
return Task.FromResult(new CallResult(null));
}
/// <summary>

View File

@ -296,20 +296,28 @@ namespace CryptoExchange.Net.Sockets
// Can't wait for this as it would cause a deadlock
_ = Task.Run(async () =>
{
var reconnectSuccessful = await ProcessReconnectAsync().ConfigureAwait(false);
if (!reconnectSuccessful)
try
{
_logger.Log(LogLevel.Warning, $"[Sckt {SocketId}] failed reconnect processing: {reconnectSuccessful.Error}, reconnecting again");
_ = _socket.ReconnectAsync().ConfigureAwait(false);
}
else
{
Status = SocketStatus.Connected;
_ = Task.Run(() =>
var reconnectSuccessful = await ProcessReconnectAsync().ConfigureAwait(false);
if (!reconnectSuccessful)
{
ConnectionRestored?.Invoke(DateTime.UtcNow - DisconnectTime!.Value);
DisconnectTime = null;
});
_logger.Log(LogLevel.Warning, $"[Sckt {SocketId}] failed reconnect processing: {reconnectSuccessful.Error}, reconnecting again");
_ = _socket.ReconnectAsync().ConfigureAwait(false);
}
else
{
Status = SocketStatus.Connected;
_ = Task.Run(() =>
{
ConnectionRestored?.Invoke(DateTime.UtcNow - DisconnectTime!.Value);
DisconnectTime = null;
});
}
}
catch(Exception ex)
{
_logger.Log(LogLevel.Warning, ex, $"[Sckt {SocketId}] Unknown exception while processing reconnection, reconnecting again");
_ = _socket.ReconnectAsync().ConfigureAwait(false);
}
});
@ -755,7 +763,7 @@ namespace CryptoExchange.Net.Sockets
if (!result)
{
_logger.Log(LogLevel.Warning, $"[Sckt {SocketId}] failed request revitalization: " + result.Error);
return result.As(false);
return result;
}
}