Fix IInstanceReferences not being disposed

Also remove unused usings
This commit is contained in:
Jordan Brown
2020-07-13 21:34:48 -04:00
parent d961186d1b
commit 46aee33261
4 changed files with 9 additions and 8 deletions
@@ -222,7 +222,8 @@ namespace Tgstation.Server.Host.Components
{
if (oldPath == null)
throw new ArgumentNullException(nameof(oldPath));
if (GetInstanceReference(instance) != null)
using var instanceReferenceCheck = GetInstanceReference(instance);
if (instanceReferenceCheck != null)
throw new InvalidOperationException("Cannot move an online instance!");
var newPath = instance.Path;
try
@@ -481,7 +481,7 @@ namespace Tgstation.Server.Host.Controllers
if (renamed)
{
var componentInstance = instanceManager.GetInstanceReference(originalModel);
using var componentInstance = instanceManager.GetInstanceReference(originalModel);
if (componentInstance != null)
await componentInstance.InstanceRenamed(originalModel.Name, cancellationToken).ConfigureAwait(false);
}
@@ -541,7 +541,7 @@ namespace Tgstation.Server.Host.Controllers
if (model.AutoUpdateInterval.HasValue && oldAutoUpdateInterval != model.AutoUpdateInterval)
{
var componentInstance = instanceManager.GetInstanceReference(originalModel);
using var componentInstance = instanceManager.GetInstanceReference(originalModel);
if (componentInstance != null)
await componentInstance.SetAutoUpdateInterval(model.AutoUpdateInterval.Value).ConfigureAwait(false);
}
@@ -49,7 +49,8 @@ namespace Tgstation.Server.Host.Controllers
if (ValidateInstanceOnlineStatus(instanceManager, Logger, Instance))
await DatabaseContext.Save(cancellationToken).ConfigureAwait(false);
if (instanceManager.GetInstanceReference(Instance) == null)
using var instanceReferenceCheck = instanceManager.GetInstanceReference(Instance);
if (instanceReferenceCheck == null)
return Conflict(new ErrorMessage(ErrorCode.InstanceOffline));
return null;
}
@@ -88,7 +89,9 @@ namespace Tgstation.Server.Host.Controllers
if (metadata == null)
throw new ArgumentNullException(nameof(metadata));
var online = instanceManager.GetInstanceReference(metadata) != null;
bool online;
using (var instanceReferenceCheck = instanceManager.GetInstanceReference(metadata))
online = instanceReferenceCheck != null;
if (metadata.Online.Value == online)
return false;
@@ -2,15 +2,12 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Rights;
using Tgstation.Server.Client;
using Tgstation.Server.Client.Components;
using Tgstation.Server.Host.Controllers;
using Tgstation.Server.Tests.Instance;
namespace Tgstation.Server.Tests
{