From e699e5d405792a598fdf6d0e723db52555af0492 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 28 Feb 2020 20:34:10 +0100 Subject: [PATCH] Fix possible race condition --- .../Manager/ProviderManager.cs | 18 ++++++++---------- .../MediaBrowser.Providers.csproj | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 4f1513df34..17d612199f 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -970,20 +970,18 @@ namespace MediaBrowser.Providers.Manager var id = item.Id; _logger.LogInformation("OnRefreshProgress {0} {1}", id.ToString("N", CultureInfo.InvariantCulture), progress); - if (_activeRefreshes.TryAdd(id, progress)) - { - RefreshProgress?.Invoke(this, new GenericEventArgs>(new Tuple(item, progress))); - } - else - { - // TODO: Need to hunt down the conditions for this happening - throw new Exception( + // TODO: Need to hunt down the conditions for this happening + _activeRefreshes.AddOrUpdate( + id, + (_) => throw new Exception( string.Format( CultureInfo.InvariantCulture, "Refresh for item {0} {1} is not in progress", item.GetType().Name, - item.Id.ToString("N", CultureInfo.InvariantCulture))); - } + item.Id.ToString("N", CultureInfo.InvariantCulture))), + (_, _) => progress); + + RefreshProgress?.Invoke(this, new GenericEventArgs>(new Tuple(item, progress))); } private readonly SimplePriorityQueue> _refreshQueue = diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index d0ed61c833..9c986382f2 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -22,6 +22,7 @@ netstandard2.1 false true + preview