From f87390e2185fde6b3b6fd6a49e6632bae3d0a448 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Tue, 15 Sep 2026 11:17:03 -0400 Subject: Backport pull request #18020 from jellyfin/release-12.z Stop the library monitor from refreshing against a disposed host Original-merge: 3aec32cb249ba54a9b6c0c799d2ff84848069722 Merged-by: crobibero Backported-by: Cody Robibero --- Emby.Server.Implementations/IO/FileRefresher.cs | 27 +++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'Emby.Server.Implementations/IO/FileRefresher.cs') diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.cs index f634084034..b31cf0f1f5 100644 --- a/Emby.Server.Implementations/IO/FileRefresher.cs +++ b/Emby.Server.Implementations/IO/FileRefresher.cs @@ -109,6 +109,11 @@ namespace Emby.Server.Implementations.IO lock (_timerLock) { + if (_disposed) + { + return; + } + paths = _affectedPaths.ToList(); } @@ -129,11 +134,12 @@ namespace Emby.Server.Implementations.IO private void ProcessPathChanges(List paths) { - IEnumerable itemsToRefresh = paths + var itemsToRefresh = paths .Distinct() - .Select(GetAffectedBaseItem) - .Where(item => item is not null) - .DistinctBy(x => x!.Id)!; // Removed null values in the previous .Where() + .Select(TryGetAffectedBaseItem) + .OfType() + .DistinctBy(x => x.Id) + .ToList(); foreach (var item in itemsToRefresh) { @@ -155,6 +161,19 @@ namespace Emby.Server.Implementations.IO } } + private BaseItem? TryGetAffectedBaseItem(string path) + { + try + { + return GetAffectedBaseItem(path); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error finding the item affected by changes to {Path}", path); + return null; + } + } + /// /// Gets the affected base item. /// -- cgit v1.2.3