Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-379971: Ensure ParallelAction is not waiting on _lock when no actions are running #3244

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions XenModel/Actions/ParallelAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ParallelAction : MultipleAction
private readonly int _maxNumberOfParallelActions;
private readonly int _actionsCount;
private readonly object _lock = new object();
private volatile int _completedActionsCount ;
private volatile int _completedActionsCount;

/// <summary>
/// Use this constructor to create a cross connection ParallelAction.
Expand Down Expand Up @@ -124,7 +124,10 @@ protected override void RunSubActions(List<Exception> exceptions)

lock (_lock)
{
Monitor.Wait(_lock);
// CA-379971: There is a chance that all actions have completed before we
// hit the Wait call, we need to make sure we don't hit a deadlock
if (_completedActionsCount != _actionsCount)
Monitor.Wait(_lock);
}
}

Expand Down Expand Up @@ -165,7 +168,7 @@ protected override void RecalculatePercentComplete()

foreach (var connection in _actionsByConnection.Keys)
{
foreach (var action in _actionsByConnection[connection])
foreach (var action in _actionsByConnection[connection])
total += action.PercentComplete;
}

Expand All @@ -180,7 +183,7 @@ private void action_Completed(ActionBase sender)
sender.Completed -= action_Completed;
lock (_lock)
{
_completedActionsCount++;
_completedActionsCount = _completedActionsCount + 1;
danilo-delbusso marked this conversation as resolved.
Show resolved Hide resolved
if (_completedActionsCount == _actionsCount)
{
Monitor.Pulse(_lock);
Expand Down
Loading