Fix issues with rare Remora bug

This commit is contained in:
Jordan Brown
2021-08-24 10:45:29 -04:00
parent 6abcfe18f2
commit a3a09f1608
2 changed files with 8 additions and 19 deletions
@@ -603,9 +603,11 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
await Task.WhenAny(gatewayReadyTcs.Task, gatewayTask).ConfigureAwait(false);
}
if (gatewayTask.IsCompleted)
if (gatewayTask.IsCompleted || cancellationToken.IsCancellationRequested)
{
await DisconnectImpl(cancellationToken).ConfigureAwait(false);
// DCT: Musn't abort
await DisconnectImpl(default).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
throw new JobException(ErrorCode.ChatCannotConnectProvider);
}
@@ -618,8 +620,9 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
Logger.LogWarning("Unable to retrieve current user: {0}", currentUserResult.Error.Message);
// will handle cleanup
await DisconnectImpl(cancellationToken).ConfigureAwait(false);
// DCT: Musn't abort
await DisconnectImpl(default).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
throw new JobException(ErrorCode.ChatCannotConnectProvider);
}
@@ -627,8 +630,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
catch (OperationCanceledException)
{
if (gatewayTask != null)
await DisconnectImpl(default).ConfigureAwait(false); // DCT: Musn't abort
throw;
}
catch (Exception e)
{
@@ -85,19 +85,6 @@ namespace Tgstation.Server.Host.Components.Chat.Providers.Tests
await provider.Disconnect(default).ConfigureAwait(false);
Assert.IsFalse(provider.Connected);
//now try it with cancellationTokens
using var cts = new CancellationTokenSource();
cts.Cancel();
var cancellationToken = cts.Token;
await Assert.ThrowsExceptionAsync<OperationCanceledException>(() => InvokeConnect(provider, cancellationToken)).ConfigureAwait(false);
Assert.IsFalse(provider.Connected);
await InvokeConnect(provider).ConfigureAwait(false);
Assert.IsTrue(provider.Connected);
await Assert.ThrowsExceptionAsync<OperationCanceledException>(() => provider.Disconnect(cancellationToken)).ConfigureAwait(false);
Assert.IsTrue(provider.Connected);
await provider.Disconnect(default).ConfigureAwait(false);
Assert.IsFalse(provider.Connected);
}
}
}