From 882e08f0e13201c414d15c0ebf75b93949792e1f Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 18 Nov 2023 22:16:34 -0500 Subject: [PATCH] More guards against sending topic requests while the server is starting or rebooting --- .../Components/Session/SessionController.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Session/SessionController.cs b/src/Tgstation.Server.Host/Components/Session/SessionController.cs index 16f0661852..e6db00c545 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionController.cs @@ -432,18 +432,32 @@ namespace Tgstation.Server.Host.Components.Session return null; } + var rebootGate = RebootGate; + var launchResult = await LaunchResult.WaitAsync(cancellationToken); + if (launchResult.ExitCode.HasValue) + { + Logger.LogDebug("Not sending topic request {commandType} to server that failed to launch!", parameters.CommandType); + return null; + } + + // meh, this is kind of a hack, but it works + if (!chatTrackingContext.Active) + { + Logger.LogDebug("Not sending topic request {commandType} to server that is rebooting/starting.", parameters.CommandType); + return null; + } + using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); var combinedCancellationToken = cts.Token; async ValueTask CancelIfLifetimeElapses() { try { - var lifetime = Lifetime; - var completed = await Task.WhenAny(lifetime, RebootGate).WaitAsync(combinedCancellationToken); + var completed = await Task.WhenAny(Lifetime, rebootGate).WaitAsync(combinedCancellationToken); Logger.LogDebug( "Server {action}, cancelling pending command: {commandType}", - completed == lifetime + completed != rebootGate ? "process ended" : "rebooting", parameters.CommandType);