diff --git a/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs b/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs index 0aba902d06..eac4b39a01 100644 --- a/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs +++ b/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs @@ -79,11 +79,21 @@ namespace Tgstation.Server.Host.Components { Models.WatchdogReattachInformation result = null; await databaseContextFactory.UseContext(async (db) => - result = await db.Instances.Where(x => x.Id == metadata.Id).Select(x => x.WatchdogReattachInformation).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false) - ).ConfigureAwait(false); + { + var instance = await db.Instances.Where(x => x.Id == metadata.Id) + .Include(x => x.WatchdogReattachInformation).ThenInclude(x => x.Alpha) + .Include(x => x.WatchdogReattachInformation).ThenInclude(x => x.Alpha) + .FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); + result = instance.WatchdogReattachInformation; + if (result == default) + return; + instance.WatchdogReattachInformation = null; + db.WatchdogReattachInformations.Remove(result); + await db.Save(cancellationToken).ConfigureAwait(false); + }).ConfigureAwait(false); if (result == default) - throw new JobException("Unable to load reattach information!"); + return null; var bravoDmbTask = dmbFactory.FromCompileJob(result.Bravo.CompileJob, cancellationToken); return new WatchdogReattachInformation(result, await dmbFactory.FromCompileJob(result.Alpha.CompileJob, cancellationToken).ConfigureAwait(false), await bravoDmbTask.ConfigureAwait(false)); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs index 20b1115531..f017a51ed1 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs @@ -361,7 +361,7 @@ namespace Tgstation.Server.Host.Components.Watchdog reattachInformation.Dmb = null; released = true; Dispose(); - Dmb.KeepAlive(); + tmpProvider.KeepAlive(); reattachInformation.Dmb = tmpProvider; return reattachInformation; } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs index e0f82236a9..b91af00859 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs @@ -625,12 +625,16 @@ namespace Tgstation.Server.Host.Components.Watchdog return null; } + var reattachInfoTask = doReattach ? reattachInfoHandler.Load(cancellationToken) : Task.FromResult(null); Task chatTask; //this is necessary, the monitor could be in it's sleep loop trying to restart if (startMonitor && await StopMonitor().ConfigureAwait(false)) chatTask = chat.SendWatchdogMessage("Automatic retry sequence cancelled by manual launch. Restarting...", cancellationToken); else if (announce) - chatTask = chat.SendWatchdogMessage("Starting...", cancellationToken); + { + var info = await reattachInfoTask.ConfigureAwait(false); + chatTask = chat.SendWatchdogMessage(info == null ? "Starting..." : "Reattaching...", cancellationToken); + } else chatTask = Task.CompletedTask; //start both servers @@ -641,7 +645,7 @@ namespace Tgstation.Server.Host.Components.Watchdog if (alphaServer != null || bravoServer != null) throw new InvalidOperationException("Entered LaunchNoLock with one or more of the servers not being null!"); - var reattachInfo = doReattach ? await reattachInfoHandler.Load(cancellationToken).ConfigureAwait(false) : null; + var reattachInfo = await reattachInfoTask.ConfigureAwait(false); var doesntNeedNewDmb = doReattach && reattachInfo.Alpha != null && reattachInfo.Bravo != null; var dmbToUse = doesntNeedNewDmb ? null : dmbFactory.LockNextDmb(2); @@ -798,6 +802,9 @@ namespace Tgstation.Server.Host.Components.Watchdog { if (releaseServers && Running) { + var chatTask = chat.SendWatchdogMessage("Detaching...", cancellationToken); + await StopMonitor().ConfigureAwait(false); + var reattachInformation = new WatchdogReattachInformation { AlphaIsActive = AlphaIsActive @@ -805,6 +812,7 @@ namespace Tgstation.Server.Host.Components.Watchdog reattachInformation.Alpha = alphaServer?.Release(); reattachInformation.Bravo = bravoServer?.Release(); await reattachInfoHandler.Save(reattachInformation, cancellationToken).ConfigureAwait(false); + await chatTask.ConfigureAwait(false); } await Terminate(false, cancellationToken).ConfigureAwait(false); }