Skip to content

Commit d08a14c

Browse files
Yield in task continuation to prevent stack overflow (#78902)
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2428510
2 parents 168eec4 + 87e0fde commit d08a14c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/EditorFeatures/Core/IntelliSense/ModelComputation.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ public void ChainTaskAndNotifyControllerWhenFinished(
146146

147147
async Task<TModel> TransformModelAsync(Task<TModel> lastTask)
148148
{
149-
// Ensure we're on the BG before doing any model transformation work.
150-
await TaskScheduler.Default;
149+
// Ensure we're on the BG before doing any model transformation work. Also, ensure we yield so that we don't
150+
// end up with an enormously long chain of tasks unwinding. That can otherwise cause a stack overflow if
151+
// this chain gets too long.
152+
await Task.Yield().ConfigureAwait(false);
151153
var model = await lastTask.ConfigureAwait(false);
152154
return await transformModelAsync(model, _stopCancellationToken).ConfigureAwait(false);
153155
}

0 commit comments

Comments
 (0)