Skip to content

Commit 62082a5

Browse files
author
Lifeng Lu
committed
Move a condition check inside RemoveDependingSynchronousTask to one of its callers.
That condition check is not necessary during cleanup when a dependency is removed. When ref-count of completed syncTask is left behind due to the earlier error (mismatching logic), this one can prevent the left behind refcount to be cleaned up, and will leave it behind even when the circular loop is removed. Due to the new logic skip rescanning when it thinks no circular reference can be formed more aggresively, it will remain in the graph for long time without being cleaned up.
1 parent 3e85f7e commit 62082a5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Microsoft.VisualStudio.Threading/JoinableTaskDependencyGraph.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,11 @@ internal static void OnSynchronousTaskEndToBlockWaiting(JoinableTask syncTask)
502502
lock (syncTask.Factory.Context.SyncContextLock)
503503
{
504504
// Remove itself from the tracking list, after the task is completed.
505-
RemoveDependingSynchronousTask(syncTask, syncTask, force: true);
505+
var syncTaskItem = (IJoinableTaskDependent)syncTask;
506+
if (syncTaskItem.GetJoinableTaskDependentData().dependingSynchronousTaskTracking is object)
507+
{
508+
RemoveDependingSynchronousTask(syncTask, syncTask, force: true);
509+
}
506510

507511
if (syncTask.PotentialUnreachableDependents is object && syncTask.PotentialUnreachableDependents.Count > 0)
508512
{
@@ -849,11 +853,7 @@ private static void RemoveDependingSynchronousTask(IJoinableTaskDependent taskOr
849853
Requires.NotNull(syncTask, nameof(syncTask));
850854
Assumes.True(Monitor.IsEntered(taskOrCollection.JoinableTaskContext.SyncContextLock));
851855

852-
var syncTaskItem = (IJoinableTaskDependent)syncTask;
853-
if (syncTaskItem.GetJoinableTaskDependentData().dependingSynchronousTaskTracking is object)
854-
{
855-
RemoveDependingSynchronousTaskFrom(new IJoinableTaskDependent[] { taskOrCollection }, syncTask, force);
856-
}
856+
RemoveDependingSynchronousTaskFrom(new IJoinableTaskDependent[] { taskOrCollection }, syncTask, force);
857857
}
858858

859859
/// <summary>

0 commit comments

Comments
 (0)