From 3b932420d3ca70c045133628151843e7b6429b4c Mon Sep 17 00:00:00 2001 From: Professor Fartsalot Date: Tue, 9 Sep 2025 14:54:18 -0400 Subject: [PATCH] Fix connection issues once and for all + Theory behind this is that on connect, they get a connection ID. On disconnect, that connection id is removed from their redis set. If they have no remaining keys, they're disposed, otherwise we can be sure they've reconnected and should not be disposed. --- .../MareSynchronosServer/Hubs/MareHub.Functions.cs | 2 ++ .../MareSynchronosServer/Hubs/MareHub.cs | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs index c1a7944..086ca69 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs @@ -202,6 +202,8 @@ public partial class MareHub private async Task UpdateUserOnRedis() { await _redis.AddAsync("UID:" + UserUID, UserCharaIdent, TimeSpan.FromSeconds(60), StackExchange.Redis.When.Always, StackExchange.Redis.CommandFlags.FireAndForget).ConfigureAwait(false); + await _redis.SetAddAsync($"connections:{UserCharaIdent}", Context.ConnectionId).ConfigureAwait(false); + await _redis.UpdateExpiryAsync($"connections:{UserCharaIdent}", TimeSpan.FromSeconds(60)).ConfigureAwait(false); } private async Task UserGroupLeave(GroupPair groupUserPair, List allUserPairs, string userIdent, string? uid = null) diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs index af4c023..388bbd6 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs @@ -136,13 +136,17 @@ public partial class MareHub : Hub, IMareHub _mareMetrics.DecGaugeWithLabels(MetricsAPI.GaugeConnections, labels: Continent); try { - _logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent)); - if (exception != null) - _logger.LogCallWarning(MareHubLogger.Args(_contextAccessor.GetIpAddress(), exception.Message, exception.StackTrace)); - + _logger.LogCallInfo(MareHubLogger.Args(_contextAccessor.GetIpAddress(), UserCharaIdent)); + if (exception != null) + _logger.LogCallWarning(MareHubLogger.Args(_contextAccessor.GetIpAddress(), exception.Message, exception.StackTrace)); + await _redis.SetRemoveAsync($"connections:{UserCharaIdent}", Context.ConnectionId).ConfigureAwait(false); + var connections = await _redis.SetMembersAsync($"connections:{UserCharaIdent}").ConfigureAwait(false); + if (connections.Length == 0) + { await GposeLobbyLeave().ConfigureAwait(false); await RemoveUserFromRedis().ConfigureAwait(false); await SendOfflineToAllPairedUsers().ConfigureAwait(false); + } } catch { }