From 906d75e8ad0be04c69d06da9ba25ab2077d09d02 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 9 Nov 2024 15:29:55 -0500 Subject: [PATCH] Fix bad engine installs not getting cleaned up --- .../Components/Engine/EngineManager.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Engine/EngineManager.cs b/src/Tgstation.Server.Host/Components/Engine/EngineManager.cs index 9b1d5b61f6..113a0d249b 100644 --- a/src/Tgstation.Server.Host/Components/Engine/EngineManager.cs +++ b/src/Tgstation.Server.Host/Components/Engine/EngineManager.cs @@ -456,6 +456,7 @@ async ValueTask AssertAndLockVersion( } // okay up to us to install it then + string? installPath = null; try { if (customVersionStream != null) @@ -475,15 +476,26 @@ async ValueTask AssertAndLockVersion( var versionString = version.ToString(); await eventConsumer.HandleEvent(EventType.EngineInstallStart, new List { versionString }, deploymentPipelineProcesses, cancellationToken); - await InstallVersionFiles(progressReporter, version, customVersionStream, deploymentPipelineProcesses, cancellationToken); - + installPath = await InstallVersionFiles(progressReporter, version, customVersionStream, deploymentPipelineProcesses, cancellationToken); await eventConsumer.HandleEvent(EventType.EngineInstallComplete, new List { versionString }, deploymentPipelineProcesses, cancellationToken); ourTcs.SetResult(); } catch (Exception ex) { - if (ex is not OperationCanceledException) + if (installPath != null) + { + try + { + logger.LogDebug("Cleaning up failed installation at {path}...", installPath); + await ioManager.DeleteDirectory(installPath, cancellationToken); + } + catch (Exception ex2) + { + logger.LogError(ex2, "Error cleaning up failed installation!"); + } + } + else if (ex is not OperationCanceledException) await eventConsumer.HandleEvent(EventType.EngineInstallFail, new List { ex.Message }, deploymentPipelineProcesses, cancellationToken); lock (installedVersions) @@ -510,8 +522,8 @@ async ValueTask AssertAndLockVersion( /// Custom zip file to use. Will cause a number to be added. /// If processes should be launched as part of the deployment pipeline. /// The for the operation. - /// A representing the running operation. - async ValueTask InstallVersionFiles( + /// A resulting in the directory the engine was installed to. + async ValueTask InstallVersionFiles( JobProgressReporter progressReporter, EngineVersion version, Stream? customVersionStream, @@ -597,6 +609,8 @@ await ioManager.WriteAllBytes( await ioManager.DeleteDirectory(installFullPath, cancellationToken); throw; } + + return installFullPath; } ///