Skip to content

Commit

Permalink
Fix race in GetOpenDocumentInCurrentContextWithChanges
Browse files Browse the repository at this point in the history
This was reading Workspace.CurrentSolution twice, so if the document
was removed between two reads it'd end up throwing exceptions or
triggering asserts.
  • Loading branch information
jasonmalinowski committed Mar 16, 2019
1 parent aaa7451 commit 6bfb43d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Workspaces/Core/Portable/Workspace/TextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ public static Document GetOpenDocumentInCurrentContextWithChanges(this SourceTex
{
if (Workspace.TryGetWorkspace(text.Container, out var workspace))
{
var solution = workspace.CurrentSolution;
var id = workspace.GetDocumentIdInCurrentContext(text.Container);
if (id == null || !workspace.CurrentSolution.ContainsDocument(id))
if (id == null || !solution.ContainsDocument(id))
{
return null;
}

var sol = workspace.CurrentSolution.WithDocumentText(id, text, PreservationMode.PreserveIdentity);
return sol.GetDocument(id);
return solution.WithDocumentText(id, text, PreservationMode.PreserveIdentity)
.GetDocument(id);
}

return null;
Expand Down

0 comments on commit 6bfb43d

Please sign in to comment.