mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-18 23:13:06 +03:00
Fix stack overflow while scanning (#15698)
This commit is contained in:
@@ -242,7 +242,7 @@ public sealed class LimitedConcurrencyLibraryScheduler : ILimitedConcurrencyLibr
|
|||||||
};
|
};
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
if (ShouldForceSequentialOperation())
|
if (ShouldForceSequentialOperation() || _deadlockDetector.Value is not null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Process sequentially.");
|
_logger.LogDebug("Process sequentially.");
|
||||||
try
|
try
|
||||||
@@ -267,32 +267,11 @@ public sealed class LimitedConcurrencyLibraryScheduler : ILimitedConcurrencyLibr
|
|||||||
_tasks.Add(item, CancellationToken.None);
|
_tasks.Add(item, CancellationToken.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_deadlockDetector.Value is not null)
|
Worker();
|
||||||
{
|
_logger.LogDebug("Wait for {NoWorkers} to complete.", workItems.Length);
|
||||||
_logger.LogDebug("Nested invocation detected, process in-place.");
|
await Task.WhenAll([.. workItems.Select(f => f.Done.Task)]).ConfigureAwait(false);
|
||||||
try
|
_logger.LogDebug("{NoWorkers} completed.", workItems.Length);
|
||||||
{
|
ScheduleTaskCleanup();
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
Reference in New Issue
Block a user