提交 ef8fa26e 编写于 作者: S Sam Harwell

Fix race condition in Document.GetSemanticModelAsync

Fixes #25836
上级 bf2141ea
......@@ -276,16 +276,19 @@ public async Task<SemanticModel> GetSemanticModelAsync(CancellationToken cancell
return result;
}
// it looks like someone has set it. try to reuse same semantic model
// It looks like someone has set it. Try to reuse same semantic model, or assign the new model if that
// fails. The lock is required since there is no compare-and-set primitive for WeakReference<T>.
lock (original)
{
if (original.TryGetTarget(out semanticModel))
{
return semanticModel;
}
// it looks like cache is gone. reset the cache.
original.SetTarget(result);
return result;
}
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册