aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormyzhysz <myzhysz@users.noreply.github.com>2025-12-28 07:22:19 -0500
committerBond_009 <bond.009@outlook.com>2025-12-28 07:22:19 -0500
commit580585846b618bf308ebfd4e698ff0efe1a2de4d (patch)
treecef771760613b74c039cc23a08052fa04f4b018a
parent1af1c72e81c3100c5db1a58d853818910c125c10 (diff)
Backport pull request #15698 from jellyfin/release-10.11.z
Fix stack overflow during scan (#15000) Original-merge: dde70fd8a2007f52f87546eb3c3acf8963333c4c Merged-by: crobibero <cody@robibe.ro> Backported-by: Bond_009 <bond.009@outlook.com>
-rw-r--r--MediaBrowser.Controller/LibraryTaskScheduler/LimitedConcurrencyLibraryScheduler.cs33
1 files changed, 6 insertions, 27 deletions
diff --git a/MediaBrowser.Controller/LibraryTaskScheduler/LimitedConcurrencyLibraryScheduler.cs b/MediaBrowser.Controller/LibraryTaskScheduler/LimitedConcurrencyLibraryScheduler.cs
index 5c805e9e4..2811a081a 100644
--- a/MediaBrowser.Controller/LibraryTaskScheduler/LimitedConcurrencyLibraryScheduler.cs
+++ b/MediaBrowser.Controller/LibraryTaskScheduler/LimitedConcurrencyLibraryScheduler.cs
@@ -243,7 +243,7 @@ public sealed class LimitedConcurrencyLibraryScheduler : ILimitedConcurrencyLibr
};
}).ToArray();
- if (ShouldForceSequentialOperation())
+ if (ShouldForceSequentialOperation() || _deadlockDetector.Value is not null)
{
_logger.LogDebug("Process sequentially.");
try
@@ -268,32 +268,11 @@ public sealed class LimitedConcurrencyLibraryScheduler : ILimitedConcurrencyLibr
await _tasks.Writer.WriteAsync(item, CancellationToken.None).ConfigureAwait(false);
}
- if (_deadlockDetector.Value is not null)
- {
- _logger.LogDebug("Nested invocation detected, process in-place.");
- try
- {
- // we are in a nested loop. There is no reason to spawn a task here as that would just lead to deadlocks and no additional concurrency is achieved
- while (workItems.Any(e => !e.Done.Task.IsCompleted) && _tasks.TryTake(out var item, 200, _deadlockDetector.Value.Token))
- {
- await ProcessItem(item).ConfigureAwait(false);
- }
- }
- catch (OperationCanceledException) when (_deadlockDetector.Value.IsCancellationRequested)
- {
- // operation is cancelled. Do nothing.
- }
-
- _logger.LogDebug("process in-place done.");
- }
- else
- {
- Worker();
- _logger.LogDebug("Wait for {NoWorkers} to complete.", workItems.Length);
- await Task.WhenAll([.. workItems.Select(f => f.Done.Task)]).ConfigureAwait(false);
- _logger.LogDebug("{NoWorkers} completed.", workItems.Length);
- ScheduleTaskCleanup();
- }
+ Worker();
+ _logger.LogDebug("Wait for {NoWorkers} to complete.", workItems.Length);
+ await Task.WhenAll([.. workItems.Select(f => f.Done.Task)]).ConfigureAwait(false);
+ _logger.LogDebug("{NoWorkers} completed.", workItems.Length);
+ ScheduleTaskCleanup();
}
/// <inheritdoc/>