diff --git a/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs b/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs index 2847789197..345a8c9411 100644 --- a/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs +++ b/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs @@ -280,6 +280,8 @@ private async ValueTask onConnect(SocketsHttpConnectionContext context, // This issue is being tracked at https://github.com/dotnet/runtime/issues/26177 and expected to be fixed in .NET 6. if (useIPv6) { + CancellationTokenSource quickFailCts = null; + CancellationTokenSource linkedTokenSource = null; try { var localToken = cancellationToken; @@ -287,8 +289,8 @@ private async ValueTask onConnect(SocketsHttpConnectionContext context, if (!hasResolvedIPv6Availability) { // to make things move fast, use a very low timeout for the initial ipv6 attempt. - var quickFailCts = new CancellationTokenSource(connection_establish_timeout); - var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, quickFailCts.Token); + quickFailCts = new CancellationTokenSource(connection_establish_timeout); + linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, quickFailCts.Token); localToken = linkedTokenSource.Token; } @@ -305,6 +307,8 @@ private async ValueTask onConnect(SocketsHttpConnectionContext context, finally { hasResolvedIPv6Availability = true; + linkedTokenSource?.Dispose(); + quickFailCts?.Dispose(); } } diff --git a/src/NzbDrone.Core/Jobs/Scheduler.cs b/src/NzbDrone.Core/Jobs/Scheduler.cs index 54e243467a..ccf46015ae 100644 --- a/src/NzbDrone.Core/Jobs/Scheduler.cs +++ b/src/NzbDrone.Core/Jobs/Scheduler.cs @@ -65,6 +65,7 @@ public void Handle(ApplicationShutdownRequested message) { _logger.Info("Shutting down scheduler"); _cancellationTokenSource.Cancel(true); + _cancellationTokenSource.Dispose(); Timer.Stop(); } } diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs b/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs index 9a6f01edc5..d8dc0409bf 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs @@ -147,6 +147,7 @@ public void Handle(ApplicationShutdownRequested message) { _logger.Info("Shutting down task execution"); _cancellationTokenSource.Cancel(true); + _cancellationTokenSource.Dispose(); } } } diff --git a/src/NzbDrone.Integration.Test/IntegrationTestBase.cs b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs index 48913fedde..33ffe27fe5 100644 --- a/src/NzbDrone.Integration.Test/IntegrationTestBase.cs +++ b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs @@ -60,6 +60,7 @@ public abstract class IntegrationTestBase private List _signalRReceived; private HubConnection _signalrConnection; + private CancellationTokenSource _signalrCts; protected IEnumerable SignalRMessages => _signalRReceived; @@ -148,6 +149,12 @@ public async Task IntegrationTearDown() _signalRReceived = new List(); } + if (_signalrCts != null) + { + _signalrCts.Dispose(); + _signalrCts = null; + } + if (Directory.Exists(TempDirectory)) { try @@ -174,11 +181,11 @@ protected async Task ConnectSignalR() _signalRReceived = new List(); _signalrConnection = new HubConnectionBuilder().WithUrl("http://localhost:7878/signalr/messages").Build(); - var cts = new CancellationTokenSource(); + _signalrCts = new CancellationTokenSource(); _signalrConnection.Closed += e => { - cts.Cancel(); + _signalrCts.Cancel(); return Task.CompletedTask; };