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