Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
[Core] Fix a stack overflow exception bubbled via the msbuild builder
Browse files Browse the repository at this point in the history
The code before would hold the lock while exiting, thus forcing the continuation to run under the lock. This ended up causing Exit tasks to be chained on the same stack frame, ending up in a stack overflow for solutions which queued a lot of builders.

Fixes #3649
  • Loading branch information
Therzok committed Jan 16, 2018
1 parent 2840ad5 commit 86f5d22
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -75,13 +75,15 @@ public Task<IDisposable> EnterAsync ()

void Exit ()
{
TaskCompletionSource<IDisposable> cs = null;
lock (queue) {
if (queue.Count > 0) {
var cs = queue.Dequeue ();
cs.SetResult (criticalSectionDisposer);
cs = queue.Dequeue ();
} else
locked = false;
}
// Set the result outside the lock, otherwise this can lead to stack overflow on task continuations.
cs?.SetResult (criticalSectionDisposer);
}
}
}
Expand Down

0 comments on commit 86f5d22

Please sign in to comment.