Safer instance manager shutdown

This commit is contained in:
Dominion
2023-04-02 21:48:57 -04:00
parent 29f070f21a
commit e08d5ede1a
@@ -461,14 +461,27 @@ namespace Tgstation.Server.Host.Components
logger.LogDebug("Stopping instance manager...");
var instanceFactoryStopTask = instanceFactory.StopAsync(cancellationToken);
await jobManager.StopAsync(cancellationToken);
await Task.WhenAll(instances.Select(x => x.Value.Instance.StopAsync(cancellationToken)));
async Task OfflineInstanceImmediate(IInstance instance, CancellationToken cancellationToken)
{
try
{
await instance.StopAsync(cancellationToken);
}
catch (Exception ex)
{
logger.LogError(ex, "Instance shutdown exception!");
}
}
await Task.WhenAll(instances.Select(x => OfflineInstanceImmediate(x.Value.Instance, cancellationToken)));
await instanceFactoryStopTask;
await swarmService.Shutdown(cancellationToken);
}
catch (Exception ex)
{
logger.LogError(ex, "Instance manager stop exception!");
logger.LogCritical(ex, "Instance manager stop exception!");
}
}