From 5967c178d412588f424d50cbbeafba6c4d8b738b Mon Sep 17 00:00:00 2001 From: Dominion Date: Sat, 20 May 2023 19:15:31 -0400 Subject: [PATCH] Update chat tracking contexts after reattaching Fixes #1490 --- .../Components/Chat/ChatManager.cs | 22 +++++++++++-------- .../Components/Chat/IChatManager.cs | 7 ++++++ .../Components/Watchdog/WatchdogBase.cs | 3 +++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs index ddd0aff92b..a1623b312c 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs @@ -232,7 +232,6 @@ namespace Tgstation.Server.Host.Components.Chat channelIdCounter += (ulong)results.Count; } - Task trackingContextUpdateTask; lock (mappedChannels) { lock (providers) @@ -245,16 +244,9 @@ namespace Tgstation.Server.Host.Components.Chat mappedChannels.Add(newId, newMapping); newMapping.Channel.RealId = newId; } - - lock (trackingContexts) - trackingContextUpdateTask = Task.WhenAll( - trackingContexts.Select( - x => x.UpdateChannels( - mappedChannels.Select(y => y.Value.Channel).ToList(), - cancellationToken))); } - await trackingContextUpdateTask; + await UpdateTrackingContexts(cancellationToken); } finally { @@ -472,6 +464,18 @@ namespace Tgstation.Server.Host.Components.Chat return context; } + /// + public Task UpdateTrackingContexts(CancellationToken cancellationToken) + { + lock (mappedChannels) + lock (trackingContexts) + return Task.WhenAll( + trackingContexts.Select( + x => x.UpdateChannels( + mappedChannels.Select(y => y.Value.Channel).ToList(), + cancellationToken))); + } + /// public void RegisterCommandHandler(ICustomCommandHandler customCommandHandler) { diff --git a/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs b/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs index cb0265c334..6518f1c894 100644 --- a/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs +++ b/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs @@ -84,5 +84,12 @@ namespace Tgstation.Server.Host.Components.Chat /// /// A new . IChatTrackingContext CreateTrackingContext(); + + /// + /// Force an update with the active channels on all active s. + /// + /// The for the operation. + /// A representing the running operation. + Task UpdateTrackingContexts(CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs index e2b1a6b7dc..5188d636b3 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs @@ -384,8 +384,11 @@ namespace Tgstation.Server.Host.Components.Watchdog { if (core.Watchdog != this) throw new InvalidOperationException(Instance.DifferentCoreExceptionMessage); + using (await SemaphoreSlimContext.Lock(synchronizationSemaphore, ct)) await LaunchNoLock(true, true, true, reattachInfo, ct); + + await Chat.UpdateTrackingContexts(ct); }, cancellationToken) ;