The Free Software Media System - Server Backend & API
Properly forward cancellationTokens
Bond_009e9f22303a4ff
diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.csindex 938ce5fbf0..8351630879 100644--- a/Emby.Dlna/PlayTo/Device.cs+++ b/Emby.Dlna/PlayTo/Device.cs@@ -235,7 +235,13 @@ namespace Emby.Dlna.PlayTo_logger.LogDebug("Setting mute");var value = mute ? 1 : 0;- await new SsdpHttpClient(_httpClientFactory).SendCommandAsync(Properties.BaseUrl, service, command.Name, rendererCommands.BuildPost(command, service.ServiceType, value))+ await new SsdpHttpClient(_httpClientFactory)+ .SendCommandAsync(+ Properties.BaseUrl,+ service,+ command.Name,+ rendererCommands.BuildPost(command, service.ServiceType, value),+ cancellationToken: cancellationToken).ConfigureAwait(false);IsMuted = mute;@@ -270,7 +276,13 @@ namespace Emby.Dlna.PlayTo// Remote control will perform betterVolume = value;- await new SsdpHttpClient(_httpClientFactory).SendCommandAsync(Properties.BaseUrl, service, command.Name, rendererCommands.BuildPost(command, service.ServiceType, value))+ await new SsdpHttpClient(_httpClientFactory)+ .SendCommandAsync(+ Properties.BaseUrl,+ service,+ command.Name,+ rendererCommands.BuildPost(command, service.ServiceType, value),+ cancellationToken: cancellationToken).ConfigureAwait(false);}@@ -291,7 +303,13 @@ namespace Emby.Dlna.PlayTothrow new InvalidOperationException("Unable to find service");}- await new SsdpHttpClient(_httpClientFactory).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, string.Format(CultureInfo.InvariantCulture, "{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME"))+ await new SsdpHttpClient(_httpClientFactory)+ .SendCommandAsync(+ Properties.BaseUrl,+ service,+ command.Name,+ avCommands.BuildPost(command, service.ServiceType, string.Format(CultureInfo.InvariantCulture, "{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME"),+ cancellationToken: cancellationToken).ConfigureAwait(false);RestartTimer(true);@@ -325,14 +343,21 @@ namespace Emby.Dlna.PlayTo}var post = avCommands.BuildPost(command, service.ServiceType, url, dictionary);- await new SsdpHttpClient(_httpClientFactory).SendCommandAsync(Properties.BaseUrl, service, command.Name, post, header: header)+ await new SsdpHttpClient(_httpClientFactory)+ .SendCommandAsync(+ Properties.BaseUrl,+ service,+ command.Name,+ post,+ header: header,+ cancellationToken: cancellationToken).ConfigureAwait(false);- await Task.Delay(50).ConfigureAwait(false);+ await Task.Delay(50, cancellationToken).ConfigureAwait(false);try{- await SetPlay(avCommands, CancellationToken.None).ConfigureAwait(false);+ await SetPlay(avCommands, cancellationToken).ConfigureAwait(false);}catch{@@ -396,7 +421,13 @@ namespace Emby.Dlna.PlayTovar service = GetAvTransportService();- await new SsdpHttpClient(_httpClientFactory).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, 1))+ await new SsdpHttpClient(_httpClientFactory)+ .SendCommandAsync(+ Properties.BaseUrl,+ service,+ command.Name,+ avCommands.BuildPost(command, service.ServiceType, 1),+ cancellationToken: cancellationToken).ConfigureAwait(false);RestartTimer(true);@@ -414,7 +445,13 @@ namespace Emby.Dlna.PlayTovar service = GetAvTransportService();- await new SsdpHttpClient(_httpClientFactory).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, 1))+ await new SsdpHttpClient(_httpClientFactory)+ .SendCommandAsync(+ Properties.BaseUrl,+ service,+ command.Name,+ avCommands.BuildPost(command, service.ServiceType, 1),+ cancellationToken: cancellationToken).ConfigureAwait(false);TransportState = TransportState.Paused;diff --git a/Emby.Dlna/PlayTo/PlayToController.cs b/Emby.Dlna/PlayTo/PlayToController.csindex 315be1e8be..e4923b9eb0 100644--- a/Emby.Dlna/PlayTo/PlayToController.cs+++ b/Emby.Dlna/PlayTo/PlayToController.cs@@ -777,7 +777,7 @@ namespace Emby.Dlna.PlayTovar currentWait = 0;while (_device.TransportState != TransportState.Playing && currentWait < MaxWait){- await Task.Delay(Interval).ConfigureAwait(false);+ await Task.Delay(Interval, cancellationToken).ConfigureAwait(false);currentWait += Interval;}diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.csindex 7567ea312c..91eeb82767 100644--- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs+++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs@@ -10,6 +10,7 @@ using System.Net.Http;using System.Net.Mime;using System.Text;using System.Text.Json;+using System.Text.Json.Serialization;using System.Threading;using System.Threading.Tasks;using MediaBrowser.Common;@@ -111,7 +112,7 @@ namespace Emby.Server.Implementations.LiveTv.Listingsoptions.Headers.TryAddWithoutValidation("token", token);using var response = await Send(options, true, info, cancellationToken).ConfigureAwait(false);await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);- var dailySchedules = await JsonSerializer.DeserializeAsync<List<ScheduleDirect.Day>>(responseStream, _jsonOptions).ConfigureAwait(false);+ var dailySchedules = await JsonSerializer.DeserializeAsync<List<ScheduleDirect.Day>>(responseStream, _jsonOptions, cancellationToken).ConfigureAwait(false);_logger.LogDebug("Found {ScheduleCount} programs on {ChannelID} ScheduleDirect", dailySchedules.Count, channelId);using var programRequestOptions = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/programs");@@ -122,12 +123,12 @@ namespace Emby.Server.Implementations.LiveTv.Listingsusing var innerResponse = await Send(programRequestOptions, true, info, cancellationToken).ConfigureAwait(false);await using var innerResponseStream = await innerResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);- var programDetails = await JsonSerializer.DeserializeAsync<List<ScheduleDirect.ProgramDetails>>(innerResponseStream, _jsonOptions).ConfigureAwait(false);+ var programDetails = await JsonSerializer.DeserializeAsync<List<ScheduleDirect.ProgramDetails>>(innerResponseStream, _jsonOptions, cancellationToken).ConfigureAwait(false);var programDict = programDetails.ToDictionary(p => p.programID, y => y);- var programIdsWithImages =- programDetails.Where(p => p.hasImageArtwork).Select(p => p.programID)- .ToList();+ var programIdsWithImages = programDetails+ .Where(p => p.hasImageArtwork).Select(p => p.programID)+ .ToList();var images = await GetImageForPrograms(info, programIdsWithImages, cancellationToken).ConfigureAwait(false);@@ -182,8 +183,7 @@ namespace Emby.Server.Implementations.LiveTv.Listingsprivate static int GetSizeOrder(ScheduleDirect.ImageData image){- if (!string.IsNullOrWhiteSpace(image.height)- && int.TryParse(image.height, out int value))+ if (int.TryParse(image.height, out int value)){return value;}@@ -704,7 +704,7 @@ namespace Emby.Server.Implementations.LiveTv.ListingshttpResponse.EnsureSuccessStatusCode();await using var stream = await httpResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);using var response = httpResponse.Content;- var root = await JsonSerializer.DeserializeAsync<ScheduleDirect.Lineups>(stream, _jsonOptions).ConfigureAwait(false);+ var root = await JsonSerializer.DeserializeAsync<ScheduleDirect.Lineups>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);return root.lineups.Any(i => string.Equals(info.ListingsId, i.lineup, StringComparison.OrdinalIgnoreCase));}@@ -776,7 +776,7 @@ namespace Emby.Server.Implementations.LiveTv.Listingsusing var httpResponse = await Send(options, true, info, cancellationToken).ConfigureAwait(false);await using var stream = await httpResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);- var root = await JsonSerializer.DeserializeAsync<ScheduleDirect.Channel>(stream, _jsonOptions).ConfigureAwait(false);+ var root = await JsonSerializer.DeserializeAsync<ScheduleDirect.Channel>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);_logger.LogInformation("Found {ChannelCount} channels on the lineup on ScheduleDirect", root.map.Count);_logger.LogInformation("Mapping Stations to Channel");diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.csindex cf653f87d0..b16ccc561a 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs@@ -92,7 +92,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun{try{- await tcpClient.ConnectAsync(remoteAddress, HdHomerunManager.HdHomeRunPort).ConfigureAwait(false);+ await tcpClient.ConnectAsync(remoteAddress, HdHomerunManager.HdHomeRunPort, openCancellationToken).ConfigureAwait(false);localAddress = ((IPEndPoint)tcpClient.Client.LocalEndPoint).Address;tcpClient.Close();}diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.csindex f7507e6ba0..eeb2426f4f 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs@@ -159,7 +159,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsEnableStreamSharing = false;await DeleteTempFiles(new List<string> { TempFilePath }).ConfigureAwait(false);- });+ }, CancellationToken.None);}private void Resolve(TaskCompletionSource<bool> openTaskCompletionSource)diff --git a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.csindex cfa2c1229a..89d36ab09f 100644--- a/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs+++ b/Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs@@ -39,7 +39,7 @@ namespace Jellyfin.Api.Helpers}// Can't dispose the response as it's required up the call chain.- var response = await httpClient.GetAsync(new Uri(state.MediaPath)).ConfigureAwait(false);+ var response = await httpClient.GetAsync(new Uri(state.MediaPath), cancellationToken).ConfigureAwait(false);var contentType = response.Content.Headers.ContentType?.ToString();httpContext.Response.Headers[HeaderNames.AcceptRanges] = "none";diff --git a/MediaBrowser.Providers/Manager/ImageSaver.cs b/MediaBrowser.Providers/Manager/ImageSaver.csindex 19a42d506c..9dd87aef53 100644--- a/MediaBrowser.Providers/Manager/ImageSaver.cs+++ b/MediaBrowser.Providers/Manager/ImageSaver.cs@@ -102,10 +102,8 @@ namespace MediaBrowser.Providers.Manager{saveLocally = false;- var season = item as Season;-// If season is virtual under a physical series, save locally if using compatible convention- if (season != null && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible)+ if (item is Season season && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible){var series = season.Series;@@ -138,7 +136,7 @@ namespace MediaBrowser.Providers.Managervar memoryStream = new MemoryStream();await using (source.ConfigureAwait(false)){- await source.CopyToAsync(memoryStream).ConfigureAwait(false);+ await source.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);}source = memoryStream;diff --git a/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.csindex ef7933b1a6..e5ad0f3e09 100644--- a/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs+++ b/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs@@ -756,7 +756,10 @@ namespace MediaBrowser.Providers.Music_stopWatchMusicBrainz.Restart();using var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);- response = await _httpClientFactory.CreateClient(NamedClient.MusicBrainz).SendAsync(request).ConfigureAwait(false);+ response = await _httpClientFactory+ .CreateClient(NamedClient.MusicBrainz)+ .SendAsync(request, cancellationToken)+ .ConfigureAwait(false);// We retry a finite number of times, and only whilst MB is indicating 503 (throttling).}diff --git a/MediaBrowser.Providers/Studios/StudiosImageProvider.cs b/MediaBrowser.Providers/Studios/StudiosImageProvider.csindex 90e13f12f8..5fcf6d9aa1 100644--- a/MediaBrowser.Providers/Studios/StudiosImageProvider.cs+++ b/MediaBrowser.Providers/Studios/StudiosImageProvider.cs@@ -144,7 +144,7 @@ namespace MediaBrowser.Providers.Studiosvar httpClient = _httpClientFactory.CreateClient(NamedClient.Default);Directory.CreateDirectory(Path.GetDirectoryName(file));- await using var response = await httpClient.GetStreamAsync(url).ConfigureAwait(false);+ await using var response = await httpClient.GetStreamAsync(url, cancellationToken).ConfigureAwait(false);await using var fileStream = new FileStream(file, FileMode.Create);await response.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);}diff --git a/jellyfin.ruleset b/jellyfin.rulesetindex 371f02566b..fa09bfb66a 100644--- a/jellyfin.ruleset+++ b/jellyfin.ruleset@@ -37,6 +37,10 @@</Rules><Rules AnalyzerId="Microsoft.CodeAnalysis.FxCopAnalyzers" RuleNamespace="Microsoft.Design">+ <!-- error on CA2016: Forward the CancellationToken parameter to methods that take one+ or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token -->+ <Rule Id="CA2016" Action="Error" />+<!-- disable warning CA1031: Do not catch general exception types --><Rule Id="CA1031" Action="Info" /><!-- disable warning CA1032: Implement standard exception constructors -->