diff --git a/Agent/Phantom.Agent.Services/Backups/BackupManager.cs b/Agent/Phantom.Agent.Services/Backups/BackupManager.cs index 623aa2b..241c83c 100644 --- a/Agent/Phantom.Agent.Services/Backups/BackupManager.cs +++ b/Agent/Phantom.Agent.Services/Backups/BackupManager.cs @@ -67,6 +67,10 @@ sealed class BackupManager : IDisposable { resultBuilder.Kind = BackupCreationResultKind.BackupCancelled; logger.Warning("Backup creation was cancelled."); return null; + } catch (TimeoutException) { + resultBuilder.Kind = BackupCreationResultKind.BackupTimedOut; + logger.Warning("Backup creation timed out."); + return null; } catch (Exception e) { resultBuilder.Kind = BackupCreationResultKind.UnknownError; logger.Error(e, "Caught exception while creating an instance backup."); @@ -76,6 +80,9 @@ sealed class BackupManager : IDisposable { await dispatcher.EnableAutomaticSaving(); } catch (OperationCanceledException) { // Ignore. + } catch (TimeoutException) { + resultBuilder.Warnings |= BackupCreationWarnings.CouldNotRestoreAutomaticSaving; + logger.Warning("Timed out waiting for automatic saving to be re-enabled."); } catch (Exception e) { resultBuilder.Warnings |= BackupCreationWarnings.CouldNotRestoreAutomaticSaving; logger.Error(e, "Caught exception while enabling automatic saving after creating an instance backup."); @@ -120,6 +127,7 @@ sealed class BackupManager : IDisposable { BackupCreationResultKind.Success => "Backup created successfully.", BackupCreationResultKind.InstanceNotRunning => "Instance is not running.", BackupCreationResultKind.BackupCancelled => "Backup cancelled.", + BackupCreationResultKind.BackupTimedOut => "Backup timed out.", BackupCreationResultKind.BackupAlreadyRunning => "A backup is already being created.", BackupCreationResultKind.BackupFileAlreadyExists => "Backup with the same name already exists.", BackupCreationResultKind.CouldNotCreateBackupFolder => "Could not create backup folder.", diff --git a/Agent/Phantom.Agent.Services/Backups/BackupServerCommandDispatcher.cs b/Agent/Phantom.Agent.Services/Backups/BackupServerCommandDispatcher.cs index 5389cbe..a825f30 100644 --- a/Agent/Phantom.Agent.Services/Backups/BackupServerCommandDispatcher.cs +++ b/Agent/Phantom.Agent.Services/Backups/BackupServerCommandDispatcher.cs @@ -32,18 +32,18 @@ sealed partial class BackupServerCommandDispatcher : IDisposable { public async Task DisableAutomaticSaving() { await process.SendCommand(MinecraftCommand.SaveOff, cancellationToken); - await automaticSavingDisabled.Task.WaitAsync(cancellationToken); + await automaticSavingDisabled.Task.WaitAsync(TimeSpan.FromSeconds(30), cancellationToken); } public async Task SaveAllChunks() { // TODO Try if not flushing and waiting a few seconds before flushing reduces lag. await process.SendCommand(MinecraftCommand.SaveAll(flush: true), cancellationToken); - await savedTheGame.Task.WaitAsync(cancellationToken); + await savedTheGame.Task.WaitAsync(TimeSpan.FromMinutes(1), cancellationToken); } public async Task EnableAutomaticSaving() { await process.SendCommand(MinecraftCommand.SaveOn, cancellationToken); - await automaticSavingEnabled.Task.WaitAsync(cancellationToken); + await automaticSavingEnabled.Task.WaitAsync(TimeSpan.FromMinutes(1), cancellationToken); } private void OnOutput(object? sender, string? line) { diff --git a/Common/Phantom.Common.Data/Backups/BackupCreationResultKind.cs b/Common/Phantom.Common.Data/Backups/BackupCreationResultKind.cs index 920380e..b5d1252 100644 --- a/Common/Phantom.Common.Data/Backups/BackupCreationResultKind.cs +++ b/Common/Phantom.Common.Data/Backups/BackupCreationResultKind.cs @@ -1,15 +1,16 @@ namespace Phantom.Common.Data.Backups; public enum BackupCreationResultKind : byte { - UnknownError, - Success, - InstanceNotRunning, - BackupCancelled, - BackupAlreadyRunning, - BackupFileAlreadyExists, - CouldNotCreateBackupFolder, - CouldNotCopyWorldToTemporaryFolder, - CouldNotCreateWorldArchive + UnknownError = 0, + Success = 1, + InstanceNotRunning = 2, + BackupTimedOut = 3, + BackupCancelled = 4, + BackupAlreadyRunning = 5, + BackupFileAlreadyExists = 6, + CouldNotCreateBackupFolder = 7, + CouldNotCopyWorldToTemporaryFolder = 8, + CouldNotCreateWorldArchive = 9 } public static class BackupCreationResultSummaryExtensions {