Fix health checks and add check for reconnects

Allows the client to auto reconnect when they encountered a connection issue.
This commit is contained in:
2025-09-04 17:15:54 -04:00
parent ef39da41c4
commit ef4c463471

View File

@@ -103,9 +103,15 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
[Authorize(Policy = "Authenticated")] [Authorize(Policy = "Authenticated")]
public async Task<bool> CheckClientHealth() public async Task<bool> CheckClientHealth()
{ {
await UpdateUserOnRedis().ConfigureAwait(false); try
{
return false; await UpdateUserOnRedis().ConfigureAwait(false);
return true;
}
catch
{
return false;
}
} }
[Authorize(Policy = "Authenticated")] [Authorize(Policy = "Authenticated")]
@@ -127,18 +133,24 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
[Authorize(Policy = "Authenticated")] [Authorize(Policy = "Authenticated")]
public override async Task OnDisconnectedAsync(Exception exception) public override async Task OnDisconnectedAsync(Exception exception)
{ {
DateTime _lastdc = DateTime.UtcNow;
_mareMetrics.DecGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Continent); _mareMetrics.DecGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Continent);
try try
{ {
_logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent)); // Check DB to see if the user reconnected after this disconnect
if (exception != null) await Task.Delay(TimeSpan.FromSeconds(7)).ConfigureAwait(false);
_logger.LogCallWarning(MareHubLogger.Args(_contextAccessor.GetIpAddress(), exception.Message, exception.StackTrace)); var dbUser = await DbContext.Users.AsNoTracking().SingleOrDefaultAsync(u => u.UID == UserUID).ConfigureAwait(false);
if (dbUser != null && dbUser.LastLoggedIn < _lastdc)
{
_logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent));
if (exception != null)
_logger.LogCallWarning(MareHubLogger.Args(_contextAccessor.GetIpAddress(), exception.Message, exception.StackTrace));
await GposeLobbyLeave().ConfigureAwait(false); await GposeLobbyLeave().ConfigureAwait(false);
await RemoveUserFromRedis().ConfigureAwait(false); await RemoveUserFromRedis().ConfigureAwait(false);
await SendOfflineToAllPairedUsers().ConfigureAwait(false); await SendOfflineToAllPairedUsers().ConfigureAwait(false);
}
} }
catch { } catch { }