diff --git a/src/NzbDrone.Common/Disk/OsPath.cs b/src/NzbDrone.Common/Disk/OsPath.cs index a219c4ac77..677316b368 100644 --- a/src/NzbDrone.Common/Disk/OsPath.cs +++ b/src/NzbDrone.Common/Disk/OsPath.cs @@ -421,7 +421,7 @@ public bool Equals(OsPath other, bool ignoreTrailingSlash) { if (left.Kind != right.Kind && right.Kind != OsPathKind.Unknown) { - throw new Exception(string.Format("Cannot combine OsPaths of different platforms ('{0}' + '{1}')", left, right)); + throw new PathCombinationException("Cannot combine OsPaths of different platforms ('{0}' + '{1}')", left, right); } if (right.IsEmpty) diff --git a/src/NzbDrone.Common/Disk/PathCombinationException.cs b/src/NzbDrone.Common/Disk/PathCombinationException.cs new file mode 100644 index 0000000000..772a6e29d6 --- /dev/null +++ b/src/NzbDrone.Common/Disk/PathCombinationException.cs @@ -0,0 +1,17 @@ +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Common.Disk +{ + public class PathCombinationException : NzbDroneException + { + public PathCombinationException(string message, params object[] args) + : base(message, args) + { + } + + public PathCombinationException(string message) + : base(message) + { + } + } +} 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/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs index ba1afdf10c..feaf53fc85 100644 --- a/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs @@ -14,7 +14,7 @@ protected override HttpRequest GetHttpRequest() // Use IMDb list Export for user lists to bypass RadarrAPI caching if (Settings.ListId.StartsWith("ls", StringComparison.OrdinalIgnoreCase)) { - throw new Exception("IMDb lists of the form 'ls12345678' are no longer supported. Feel free to remove this list after you review your Clean Library Level."); + throw new NotSupportedException("IMDb lists of the form 'ls12345678' are no longer supported. Feel free to remove this list after you review your Clean Library Level."); } var request = RequestBuilder.Create() diff --git a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs index e473b3407f..610a132018 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs @@ -168,7 +168,10 @@ protected virtual string GetMagnetUrl(XElement item) if (PeersElementName.IsNotNullOrWhiteSpace()) { var itempeers = item.FindDecendants(PeersElementName).SingleOrDefault(); - return int.Parse(itempeers.Value); + if (itempeers != null) + { + return int.Parse(itempeers.Value); + } } return null; 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/MediaCover/MediaCoverService.cs b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs index 223dd0d939..55c72ae92f 100644 --- a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net; using System.Threading; +using System.Threading.Tasks; using NLog; using NzbDrone.Common; using NzbDrone.Common.Disk; @@ -141,7 +142,7 @@ private string GetMovieCoverPath(int movieId) return Path.Combine(_coverRootFolder, movieId.ToString()); } - private bool EnsureCovers(Movie movie) + private async Task EnsureCoversAsync(Movie movie) { var updated = false; var toResize = new List>(); @@ -184,7 +185,7 @@ private bool EnsureCovers(Movie movie) try { - _semaphore.Wait(); + await _semaphore.WaitAsync(); foreach (var tuple in toResize) { @@ -261,9 +262,9 @@ private static string GetExtension(MediaCoverTypes coverType) }; } - public void HandleAsync(MovieUpdatedEvent message) + public async void HandleAsync(MovieUpdatedEvent message) { - var updated = EnsureCovers(message.Movie); + var updated = await EnsureCoversAsync(message.Movie); _eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie, updated)); } 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; };