mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-12 02:16:23 +00:00
Updated revitalize request signature, added exception handler reconnect logic
This commit is contained in:
parent
68e525ab9d
commit
f917bf0e3f
@ -424,13 +424,13 @@ namespace CryptoExchange.Net
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <param name="request">The original request</param>
|
/// <param name="subscription">The subscription</param>
|
||||||
/// <returns></returns>
|
/// <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>
|
/// <summary>
|
||||||
|
@ -296,20 +296,28 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
// Can't wait for this as it would cause a deadlock
|
// Can't wait for this as it would cause a deadlock
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var reconnectSuccessful = await ProcessReconnectAsync().ConfigureAwait(false);
|
try
|
||||||
if (!reconnectSuccessful)
|
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Warning, $"[Sckt {SocketId}] failed reconnect processing: {reconnectSuccessful.Error}, reconnecting again");
|
var reconnectSuccessful = await ProcessReconnectAsync().ConfigureAwait(false);
|
||||||
_ = _socket.ReconnectAsync().ConfigureAwait(false);
|
if (!reconnectSuccessful)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Status = SocketStatus.Connected;
|
|
||||||
_ = Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
ConnectionRestored?.Invoke(DateTime.UtcNow - DisconnectTime!.Value);
|
_logger.Log(LogLevel.Warning, $"[Sckt {SocketId}] failed reconnect processing: {reconnectSuccessful.Error}, reconnecting again");
|
||||||
DisconnectTime = null;
|
_ = _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)
|
if (!result)
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Warning, $"[Sckt {SocketId}] failed request revitalization: " + result.Error);
|
_logger.Log(LogLevel.Warning, $"[Sckt {SocketId}] failed request revitalization: " + result.Error);
|
||||||
return result.As(false);
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user