From a47017d3189eef5918c71d85d7bcbafa143e9a14 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 23 Dec 2023 22:06:23 -0500 Subject: [PATCH] Nullify `SessionControllerFactory` --- .../Session/ISessionControllerFactory.cs | 2 +- .../Session/SessionControllerFactory.cs | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Session/ISessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Session/ISessionControllerFactory.cs index c6d1a634ff..7058d3f4e4 100644 --- a/src/Tgstation.Server.Host/Components/Session/ISessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Session/ISessionControllerFactory.cs @@ -34,7 +34,7 @@ namespace Tgstation.Server.Host.Components.Session /// The to use. /// The for the operation. /// A resulting in a new on success or on failure to reattach. - ValueTask Reattach( + ValueTask Reattach( ReattachInformation reattachInformation, CancellationToken cancellationToken); } diff --git a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs index 79abda99a8..70bed0f5ba 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs @@ -26,8 +26,6 @@ using Tgstation.Server.Host.Security; using Tgstation.Server.Host.System; using Tgstation.Server.Host.Utils; -#nullable disable - namespace Tgstation.Server.Host.Components.Session { /// @@ -227,7 +225,7 @@ namespace Tgstation.Server.Host.Components.Session #pragma warning disable CA1506 // TODO: Decomplexify public async ValueTask LaunchNew( IDmbProvider dmbProvider, - IEngineExecutableLock currentByondLock, + IEngineExecutableLock? currentByondLock, DreamDaemonLaunchParameters launchParameters, bool apiValidate, CancellationToken cancellationToken) @@ -270,17 +268,17 @@ namespace Tgstation.Server.Host.Components.Session dmbProvider.CompileJob.Id); // mad this isn't abstracted but whatever - var engineType = dmbProvider.EngineVersion.Engine.Value; + var engineType = dmbProvider.EngineVersion.Engine!.Value; if (engineType == EngineType.Byond) await CheckPagerIsNotRunning(); await PortBindTest(launchParameters.Port.Value, engineType, cancellationToken); - string outputFilePath = null; + string? outputFilePath = null; var preserveLogFile = true; var hasStandardOutput = engineLock.HasStandardOutput; - if (launchParameters.LogOutput.Value) + if (launchParameters.LogOutput!.Value) { var now = DateTimeOffset.UtcNow; var dateDirectory = diagnosticsIOManager.ConcatPath(DreamDaemonLogsPath, now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); @@ -322,8 +320,8 @@ namespace Tgstation.Server.Host.Components.Session var runtimeInformation = CreateRuntimeInformation( dmbProvider, chatTrackingContext, - launchParameters.SecurityLevel.Value, - launchParameters.Visibility.Value, + launchParameters.SecurityLevel!.Value, + launchParameters.Visibility!.Value, apiValidate); var reattachInformation = new ReattachInformation( @@ -335,7 +333,7 @@ namespace Tgstation.Server.Host.Components.Session var byondTopicSender = topicClientFactory.CreateTopicClient( TimeSpan.FromMilliseconds( - launchParameters.TopicRequestTimeout.Value)); + launchParameters.TopicRequestTimeout!.Value)); var sessionController = new SessionController( reattachInformation, @@ -387,7 +385,7 @@ namespace Tgstation.Server.Host.Components.Session #pragma warning restore CA1506 /// - public async ValueTask Reattach( + public async ValueTask Reattach( ReattachInformation reattachInformation, CancellationToken cancellationToken) { @@ -452,19 +450,21 @@ namespace Tgstation.Server.Host.Components.Session } catch { - chatTrackingContext.Dispose(); + chatTrackingContext?.Dispose(); throw; } } catch { - await process.DisposeAsync(); + if (process != null) + await process.DisposeAsync(); + throw; } } catch { - engineLock.Dispose(); + engineLock?.Dispose(); throw; } } @@ -476,7 +476,7 @@ namespace Tgstation.Server.Host.Components.Session /// The . /// The . /// The secure string to use for the session. - /// The full path to log DreamDaemon output to. + /// The optional full path to log DreamDaemon output to. /// If we are only validating the DMAPI then exiting. /// The for the operation. /// A resulting in the DreamDaemon . @@ -485,7 +485,7 @@ namespace Tgstation.Server.Host.Components.Session IEngineExecutableLock engineLock, DreamDaemonLaunchParameters launchParameters, string accessIdentifier, - string logFilePath, + string? logFilePath, bool apiValidate, CancellationToken cancellationToken) { @@ -557,19 +557,19 @@ namespace Tgstation.Server.Host.Components.Session /// If , will be deleted. /// The for the operation. /// A representing the running operation. - async ValueTask LogDDOutput(IProcess process, string outputFilePath, bool cliSupported, bool preserveFile, CancellationToken cancellationToken) + async ValueTask LogDDOutput(IProcess process, string? outputFilePath, bool cliSupported, bool preserveFile, CancellationToken cancellationToken) { try { - string ddOutput = null; + string? ddOutput = null; if (cliSupported) - ddOutput = await process.GetCombinedOutput(cancellationToken); + ddOutput = (await process.GetCombinedOutput(cancellationToken))!; if (ddOutput == null) try { var dreamDaemonLogBytes = await gameIOManager.ReadAllBytes( - outputFilePath, + outputFilePath!, cancellationToken); ddOutput = Encoding.UTF8.GetString(dreamDaemonLogBytes); @@ -580,7 +580,7 @@ namespace Tgstation.Server.Host.Components.Session try { logger.LogTrace("Deleting temporary log file {path}...", outputFilePath); - await gameIOManager.DeleteFile(outputFilePath, cancellationToken); + await gameIOManager.DeleteFile(outputFilePath!, cancellationToken); } catch (Exception ex) { @@ -620,7 +620,7 @@ namespace Tgstation.Server.Host.Components.Session chatTrackingContext, dmbProvider, assemblyInformationProvider.Version, - instance.Name, + instance.Name!, securityLevel, visibility, serverPortProvider.HttpApiPort,