Skip to content

Commit

Permalink
shutdown concurrency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgerlag committed Aug 8, 2020
1 parent ffca3da commit 2127e6f
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/WorkflowCore/Services/BackgroundTasks/QueueConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ private async void Execute()
{
try
{
if (activeTasks.Count >= MaxConcurrentItems)
var activeCount = 0;
lock (activeTasks)
{
activeCount = activeTasks.Count;
}
if (activeCount >= MaxConcurrentItems)
{
await Task.Delay(Options.IdleTime);
continue;
Expand All @@ -75,14 +80,19 @@ private async void Execute()
await Task.Delay(Options.IdleTime, cancelToken);
continue;
}

if (activeTasks.ContainsKey(item))

var hasTask = false;
lock (activeTasks)
{
hasTask = activeTasks.ContainsKey(item);
}
if (hasTask)
{
secondPasses.Add(item);
if (!EnableSecondPasses)
await QueueProvider.QueueWork(item, Queue);
continue;
}
}

secondPasses.TryRemove(item);

Expand Down Expand Up @@ -121,7 +131,13 @@ private async void Execute()
}
}

foreach (var task in activeTasks.Values)
List<Task> toComplete;
lock (activeTasks)
{
toComplete = activeTasks.Values.ToList();
}

foreach (var task in toComplete)
task.Wait();
}

Expand Down

0 comments on commit 2127e6f

Please sign in to comment.