Skip to content

Conversation

@DustinCampbell
Copy link
Member

Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1980614/

There are scenarios on 17.10p2 where my recent changes to make FallbackProjectManager use the dispatcher for project snapshot manager changes can cause a dead lock. The problem occurs when dynamic file info is updated on the dispatcher thread. Roslyn will then call GetDynamicFileInfoAsync(...) on the dispatcher thread and block on the result. GetDynamicFileInfoAsync(...) calls into FallbackProjectManager.DynamicFileAddedAsync(...), which attempts to make changes to the project snapshot manager using the dispatcher. However, because the dispatcher thread is blocked, it can never make progress to newly queued task and hangs.

This is a small change to FallbackProjectManager to apply the project snapshot manager changes directly if it's running on the dispatcher thread. Otherwise, it runs the change on the dispatcher.

There are scenarios on 17.10p2 where my recent changes to make
`FallbackProjectManager` use the dispatcher for project snapshot
manager changes can cause a dead lock. The problem occurs when
dynamic file info is updated on the dispatcher thread. Roslyn will then
call `GetDynamicFileInfoAsync(...)` on the dispatcher thread and block
on the result. `GetDynamicFileInfoAsync(...)` calls into
`FallbackProjectManager.DynamicFileAddedAsync(...)`, which attempts
to make changes to the project snapshot manager using the dispatcher.
However, because the dispatcher thread is blocked, it can never make
progress to newly queued task and hangs.

This is a small change to `FallbackProjectManager` to apply the
project snapshot manager changes directly if it's running on the
dispatcher thread. Otherwise, it rusn the change on the dispatcher.
@DustinCampbell DustinCampbell requested a review from a team as a code owner March 6, 2024 01:38
Comment on lines -121 to +117
.ConfigureAwait(false);
if (_dispatcher.IsDispatcherThread)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this logic just be moved into RunOnDispatcherThread ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100%! But I'm just making a small change for the 17.10p2 QB. I'll have a proper PR that updates dispatcher on main up shortly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me

Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to see this on the dispatcher itself. Alternatively, could we use some form of JTF for this?

@DustinCampbell
Copy link
Member Author

Would like to see this on the dispatcher itself. Alternatively, could we use some form of JTF for this?

Yup, it'll be on dispatcher in main. I just didn't want to make a more impactful change on the release branch.

@DustinCampbell DustinCampbell enabled auto-merge March 6, 2024 04:45
@DustinCampbell DustinCampbell merged commit c5753a9 into dotnet:release/dev17.10 Mar 6, 2024
@DustinCampbell DustinCampbell deleted the fix-hang branch March 6, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants