Code Optimizations for SignalR/ApiController
This commit is contained in:
@@ -310,7 +310,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
||||
_ = Task.Run(async () => await StopConnection(ServerState.Disconnected).ConfigureAwait(false));
|
||||
_connectionCancellationTokenSource?.Cancel();
|
||||
}
|
||||
private int _unhealthy = 0;
|
||||
|
||||
private async Task ClientHealthCheck(CancellationToken ct)
|
||||
{
|
||||
while (!ct.IsCancellationRequested && _mareHub != null)
|
||||
@@ -319,15 +319,9 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
||||
var healthy = await CheckClientHealth().ConfigureAwait(false);
|
||||
if (!healthy || _mareHub.State != HubConnectionState.Connected)
|
||||
{
|
||||
_unhealthy++;
|
||||
if (_unhealthy > 0)
|
||||
{
|
||||
Logger.LogWarning("Health check failed, forcing reconnect. ClientHealth: {0} HubConnected: {1}", healthy, _mareHub.State != HubConnectionState.Connected);
|
||||
await ForceResetConnection().ConfigureAwait(false);
|
||||
_unhealthy = 0;
|
||||
}
|
||||
Logger.LogWarning("Health check failed, forcing reconnect. ClientHealth: {0} HubConnected: {1}", healthy, _mareHub.State != HubConnectionState.Connected);
|
||||
await ForceResetConnection().ConfigureAwait(false);
|
||||
}
|
||||
else _unhealthy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user