Skip to content

Commit

Permalink
Fix bad engine installs not getting cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Nov 9, 2024
1 parent 4fe6b5a commit 906d75e
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Tgstation.Server.Host/Components/Engine/EngineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ async ValueTask<EngineExecutableLock> AssertAndLockVersion(
}

// okay up to us to install it then
string? installPath = null;
try
{
if (customVersionStream != null)
Expand All @@ -475,15 +476,26 @@ async ValueTask<EngineExecutableLock> AssertAndLockVersion(
var versionString = version.ToString();
await eventConsumer.HandleEvent(EventType.EngineInstallStart, new List<string> { 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<string> { 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<string> { ex.Message }, deploymentPipelineProcesses, cancellationToken);

lock (installedVersions)
Expand All @@ -510,8 +522,8 @@ async ValueTask<EngineExecutableLock> AssertAndLockVersion(
/// <param name="customVersionStream">Custom zip file <see cref="Stream"/> to use. Will cause a <see cref="Version.Build"/> number to be added.</param>
/// <param name="deploymentPipelineProcesses">If processes should be launched as part of the deployment pipeline.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask InstallVersionFiles(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the directory the engine was installed to.</returns>
async ValueTask<string> InstallVersionFiles(
JobProgressReporter progressReporter,
EngineVersion version,
Stream? customVersionStream,
Expand Down Expand Up @@ -597,6 +609,8 @@ await ioManager.WriteAllBytes(
await ioManager.DeleteDirectory(installFullPath, cancellationToken);
throw;
}

return installFullPath;
}

/// <summary>
Expand Down

0 comments on commit 906d75e

Please sign in to comment.