From bbb71a13f58ddecf4b07baebf5c3844e004c5bf3 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Fri, 8 May 2020 21:31:48 -0400 Subject: [PATCH] Fix reattaching again --- .../Components/Interop/DMApiParameters.cs | 2 +- .../Components/Watchdog/BasicWatchdog.cs | 14 +++---- .../Watchdog/ReattachInformation.cs | 21 ++-------- .../Models/ReattachInformationBase.cs | 2 +- src/Tgstation.Server.Host/Program.cs | 42 +++++++++---------- 5 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs b/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs index 14c8a955e6..22cfc28983 100644 --- a/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs +++ b/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs @@ -11,6 +11,6 @@ namespace Tgstation.Server.Host.Components.Interop /// Used to identify and authenticate the DreamDaemon instance /// [Required] - public virtual string AccessIdentifier { get; set; } + public string AccessIdentifier { get; set; } } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs index 064f3698a6..61050c4146 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Logging; using System; -using System.Diagnostics; using System.Globalization; using System.Threading; using System.Threading.Tasks; @@ -157,16 +156,13 @@ namespace Tgstation.Server.Host.Components.Watchdog /// protected sealed override async Task InitControllers(Action callBeforeRecurse, Task chatTask, WatchdogReattachInformation reattachInfo, CancellationToken cancellationToken) { - Debug.Assert(Server == null, "Entered LaunchNoLock with server not being null!"); - - // don't need a new dmb if reattaching - var doesntNeedNewDmb = reattachInfo?.Alpha != null && reattachInfo?.Bravo != null; - var dmbToUse = doesntNeedNewDmb ? null : DmbFactory.LockNextDmb(1); - var serverToReattach = reattachInfo?.Alpha ?? reattachInfo?.Bravo; var serverToKill = reattachInfo?.Bravo ?? reattachInfo?.Alpha; // vice versa + if (serverToKill == serverToReattach) + serverToKill = null; + if (reattachInfo?.AlphaIsActive == false) { var temp = serverToReattach; @@ -174,6 +170,10 @@ namespace Tgstation.Server.Host.Components.Watchdog serverToKill = temp; } + // don't need a new dmb if reattaching + var doesntNeedNewDmb = serverToReattach != null; + var dmbToUse = doesntNeedNewDmb ? null : DmbFactory.LockNextDmb(1); + // if this try catches something, both servers are killed bool inactiveServerWasKilled = false; try diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs b/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs index fde826dc75..0edbdd65ef 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs @@ -1,5 +1,4 @@ using System; -using Tgstation.Server.Api.Models; using Tgstation.Server.Host.Components.Deployment; using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Models; @@ -22,20 +21,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// public RuntimeInformation RuntimeInformation { get; private set; } - /// - public override DreamDaemonSecurity? LaunchSecurityLevel - { - get => RuntimeInformation.SecurityLevel ?? base.LaunchSecurityLevel; - set => throw new NotSupportedException(); - } - - /// - public override string AccessIdentifier - { - get => base.AccessIdentifier; - set => throw new NotSupportedException(); - } - /// /// for accessing . /// @@ -47,7 +32,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The value of . /// The used to get the . /// The value of . - /// The value of . + /// The value of . /// The value of . /// The value of . internal ReattachInformation( @@ -64,9 +49,9 @@ namespace Tgstation.Server.Host.Components.Watchdog if (!runtimeInformation.SecurityLevel.HasValue) throw new ArgumentException("runtimeInformation must have a valid SecurityLevel!", nameof(runtimeInformation)); - base.AccessIdentifier = accessIdentifier ?? throw new ArgumentNullException(nameof(accessIdentifier)); + AccessIdentifier = accessIdentifier ?? throw new ArgumentNullException(nameof(accessIdentifier)); - base.LaunchSecurityLevel = runtimeInformation.SecurityLevel.Value; + LaunchSecurityLevel = runtimeInformation.SecurityLevel.Value; Port = port; IsPrimary = isPrimary; diff --git a/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs b/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs index 75f8848e1e..e64976596a 100644 --- a/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs +++ b/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs @@ -36,7 +36,7 @@ namespace Tgstation.Server.Host.Models /// The level DreamDaemon was launched with. /// [Required] - public virtual DreamDaemonSecurity? LaunchSecurityLevel { get; set; } + public DreamDaemonSecurity? LaunchSecurityLevel { get; set; } /// /// Construct a diff --git a/src/Tgstation.Server.Host/Program.cs b/src/Tgstation.Server.Host/Program.cs index 8666ac642f..77d2dc2d09 100644 --- a/src/Tgstation.Server.Host/Program.cs +++ b/src/Tgstation.Server.Host/Program.cs @@ -55,30 +55,28 @@ namespace Tgstation.Server.Host var updatedArgsArray = listArgs.ToArray(); try { - using (var shutdownNotifier = new ProgramShutdownTokenSource()) + using var shutdownNotifier = new ProgramShutdownTokenSource(); + var cancellationToken = shutdownNotifier.Token; + IServer server; + try { - var cancellationToken = shutdownNotifier.Token; - IServer server; - try - { - server = await ServerFactory.CreateServer(updatedArgsArray, updatePath, cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) - { - // Console cancelled - return 0; - } - - if (server == null) - return 0; - - try - { - await server.Run(cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) { } - return server.RestartRequested ? 1 : 0; + server = await ServerFactory.CreateServer(updatedArgsArray, updatePath, cancellationToken).ConfigureAwait(false); } + catch (OperationCanceledException) + { + // Console cancelled + return 0; + } + + if (server == null) + return 0; + + try + { + await server.Run(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) { } + return server.RestartRequested ? 1 : 0; } catch (Exception e) {