Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock closing solutions with CPS projects referencing Shared Projects. #14479

Closed
mavasani opened this issue Oct 12, 2016 · 27 comments · Fixed by #16889
Closed

Deadlock closing solutions with CPS projects referencing Shared Projects. #14479

mavasani opened this issue Oct 12, 2016 · 27 comments · Fixed by #16889
Assignees
Labels
Area-IDE Bug Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner.
Milestone

Comments

@mavasani
Copy link
Contributor

mavasani commented Oct 12, 2016

I am hitting a deadlock in the CPS project system with the below callstack.
ClearProjectData method on the workspace ends up invoking SetDocumentContext within a lock, which may end up invoking back into workspace causing this deadlock. The comment here indicates we shouldn't be invoking SetDocumentContext when project/solution is closing, but it seems there are code paths like this one where we do invoke it.

    mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext) Line 203  C#
    mscorlib.dll!System.Threading.SemaphoreSlim.WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, System.Threading.CancellationToken cancellationToken) Line 469 C#
    mscorlib.dll!System.Threading.SemaphoreSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) Line 439    C#
>   Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnDocumentContextUpdated(Microsoft.CodeAnalysis.DocumentId documentId, Microsoft.CodeAnalysis.Text.SourceTextContainer container) Line 356   C#
    Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnDocumentContextUpdated(Microsoft.CodeAnalysis.DocumentId documentId) Line 349  C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.UpdateDocumentContextIfContainsDocument(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy sharedHierarchy, Microsoft.CodeAnalysis.DocumentId documentId) Line 915    C#
    Microsoft.VisualStudio.LanguageServices.dll!Roslyn.VisualStudio.ProjectSystem.HierarchyEventsSink.OnPropertyChanged(uint itemid, int propid, uint flags) Line 31    C#
    Microsoft.VisualStudio.ProjectSystem.Managed.VS.dll!Microsoft.VisualStudio.ProjectSystem.VS.LanguageServices.UnconfiguredProjectHostObject.OnPropertyChanged(uint itemid, int propid, uint flags) Line 91   C#
    Microsoft.VisualStudio.ProjectSystem.Managed.VS.dll!Microsoft.VisualStudio.ProjectSystem.VS.LanguageServices.UnconfiguredProjectHostObject.SetProperty(uint itemid, int propid, object var) Line 67 C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.SetDocumentContext(Microsoft.CodeAnalysis.DocumentId documentId) Line 883    C#
    Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ClearOpenDocument(Microsoft.CodeAnalysis.DocumentId documentId, bool isSolutionClosing) Line 97  C#
    Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ClearOpenDocuments(Microsoft.CodeAnalysis.ProjectId projectId) Line 78   C#
    Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ClearProjectData(Microsoft.CodeAnalysis.ProjectId projectId) Line 260    C#
    Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnProjectRemoved(Microsoft.CodeAnalysis.ProjectId projectId) Line 423    C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.VisualStudioWorkspaceHost.Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.IVisualStudioWorkspaceHost.OnProjectRemoved(Microsoft.CodeAnalysis.ProjectId projectId) Line 1332 C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.RemoveProject_Foreground(Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject project) Line 385 C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.RemoveProject.AnonymousMethod__0() Line 361 C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.ExecuteOrScheduleForegroundAffinitizedAction(System.Action action) Line 169 C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.RemoveProject(Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject project) Line 362    C#
    Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject.Disconnect() Line 1109 C#
    Microsoft.VisualStudio.LanguageServices.Implementation.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS.CPSProject.Disconnect() Line 54 C#
    Microsoft.VisualStudio.LanguageServices.Implementation.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS.CPSProject.Dispose() Line 156   C#
@Pilchie
Copy link
Member

Pilchie commented Oct 13, 2016

I'm pretty sure there is already a bug on @dpoeschl about this (maybe an internal one?)

@Pilchie Pilchie added this to the 2.0 (RC) milestone Oct 17, 2016
@Pilchie Pilchie added the Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner. label Oct 17, 2016
@mavasani
Copy link
Contributor Author

Another callsite for SetDocument context already ensures that it is invoked outside the lock: http://source.roslyn.io/#Microsoft.CodeAnalysis.Workspaces/Workspace/Workspace_Editor.cs,556. Might be a matter of just refactoring this code path to do the same...

mavasani added a commit to mavasani/project-system that referenced this issue Oct 18, 2016
@MattGertz MattGertz modified the milestones: 2.0 (RC), 2.0 (RC.2) Nov 4, 2016
@Pilchie Pilchie modified the milestones: 2.0 (RC.3), 2.0 (RC.2) Dec 5, 2016
@Pilchie
Copy link
Member

Pilchie commented Jan 5, 2017

See also internal bug 296432.

@Pilchie Pilchie modified the milestones: 2.0 (RTM), 2.0 (RC.3) Jan 11, 2017
@MattGertz MattGertz modified the milestones: 2.1, 2.0 (RTM) Jan 22, 2017
@Pilchie Pilchie modified the milestones: 2.0 (RTM), 2.1 Jan 23, 2017
@Pilchie
Copy link
Member

Pilchie commented Jan 23, 2017

Pulling back into RTM to investigate, since there are several reports of this.

@dpoeschl
Copy link
Contributor

dpoeschl commented Jan 25, 2017

Two observations of differences between the old & new project systems. There are a few questions in there for the CPS team (@davkean @mavasani @srivatsn). FYI @Pilchie

  1. Solution Close: In the old project system, when the solution begins closing, the shared project has already basically disconnected itself. As projects close, we try to tell the shared project hierarchy to update its "context hierarchy", but it doesn't do anything in response to that request. It has already disconnected such that even asking it for it's "context hierarchy" returns null, so it has already decided that it doesn't want to play anymore. Therefore, we don't get the hierarchy events that trigger us to OnDocumentContextUpdated and the deadlock is not hit.

    In the new project system, when the solution is closing, the shared project hierarchy is still alive and functioning while the projects are being unloaded, which triggers hierarchy events and triggers OnDocumentContextUpdated, causing the deadlock.

    Is this change in behavior of shared hierarchies during shutdown intentional in CPS? Or should it be fixed there?

  2. Project Unload: The deadlock in the new project system also occurs if you unload the active context project.

    In contrast with the Solution Close case, when a project is unloaded the shared project hierarchy has to stay active and can't just shut itself down as above. The old project system avoided this deadlock here by updating the shared project hierarchy's "context hierarchy" before removing the project. That way, when the project is removed, we try to set the "context hierarchy" to what it already is, so the hierarchy events that trigger us to OnDocumentContextUpdated do not fire.

    Is this change in behavior of shared hierarchies during project unload intentional in CPS? Or should it be fixed there?

@dpoeschl dpoeschl changed the title Deadlock during Microsoft.CodeAnalysis.Workspace.ClearProjectData Deadlock closing solutions with CPS projects referencing Shared Projects. Jan 28, 2017
@davkean
Copy link
Member

davkean commented Jan 28, 2017

Thanks David.

I need a little more context before I can say whether we should fix something here:

  1. Shared Projects have always been CPS-based, are you saying there's a behavior change here from VS 2015?

  2. You say by "solution closing, the shared project has already disconnected itself". Disconnected from what? Shared Projects don't register themselves with the workspace, what are we disconnecting ourselves from?

@davkean
Copy link
Member

davkean commented Jan 28, 2017

Basically, I don't have enough information to make any actionable changes - it's not clear what/how we would change the project system to avoid this.

@dpoeschl
Copy link
Contributor

dpoeschl commented Jan 29, 2017

@davkean Okay, I definitely should have been more clear on both fronts.

  1. Using the same, recent version of VS 2017, ".NET Framework" applications that reference shared projects work in the way I described above as the "old project system" (which naturally avoid these deadlocks). ".NET Standard" applications that reference shared projects work the way I described above as the "new project system" / "CPS" (which doesn't follow the same patterns that allow us to "automatically" avoid the deadlocks). I'm probably messing up the terminology.

    Does the difference in behavior along that axis (Framework vs. Standard) make more sense? (I have no idea what's controlling how this stuff works in either case, but there must be a difference, as described above.)

  2. The shared project hierarchy has stopped tracking & reporting its context hierarchy / responding to requests to set the context hierarchy.

@davkean
Copy link
Member

davkean commented Jan 29, 2017

Let's Skype tomorrow afternoon and walk through the code, it's still not clear to me where/how this all works on the Roslyn side.

@davkean
Copy link
Member

davkean commented Jan 30, 2017

Sorry, I looked at the stack above - you are saying that us raising OnPropertyChanged after you called SetProperty on us is causing the deadlock? If so, I get that the behavior is probably different from the legacy project system, but you just set a property on us - what would expect us to do in this situation?

@davkean
Copy link
Member

davkean commented Jan 30, 2017

Can you see if https://devdiv.visualstudio.com/DevDiv/_workitems/edit/245867 is also caused by this?

@davkean
Copy link
Member

davkean commented Jan 30, 2017

The way to think about this is; imagine that language service was only alive for half the lifetime of the project. We should be able to shut you down without the project system being required to close.

@dpoeschl
Copy link
Contributor

@davkean That bug is almost certainly a dupe.

@dpoeschl
Copy link
Contributor

Sorry, I looked at the stack above - you are saying that us raising OnPropertyChanged after you called SetProperty on us is causing the deadlock? If so, I get that the behavior is probably different from the legacy project system, but you just set a property on us - what would expect us to do in this situation?

I'd expect the same behavior as before. In the case of Project Unload, I'd expect the SharedContextHierarchy to already have been updated before the project unloads. In the case of Solution Close, I'd expect the Shared Project Hierarchy to stop listening to property sets / stop issuing events.

If that's an unrealistic hope, then I can work around this deadlock (not in a very happy way, but it works), I just worry that there might be more fallout from the behavioral differences that we haven't discovered yet.

@mavasani
Copy link
Contributor Author

Firstly, note that we have already worked around this deadlock in the project system with this commit - I don't think we need to do anything for RTM. The UnconfiguredProjectHostObject on project system side keeps track of whether or not we are currently disposing the workspace project context, and avoid attempting to raise hierarchy events during this phase, avoiding deadlock.

The deadlock here is unrelated to project systems, it can happen from any project systems that:

  1. Advise hierarchy events on the IVSHierarchy wrapping the project (see here)
  2. Attempt to invoke OnPropertyChanged during SetProperty callback for __VSHPROPID7.VSHPROPID_SharedItemContextHierarchy (see here

We just need to ensure on the Roslyn side that SetDocumentContext is never invoked within a lock - we do so at all callsites except this one, and we need to fix this.

@dpoeschl
Copy link
Contributor

dpoeschl commented Feb 1, 2017

@mavasani

Firstly, note that we have already worked around this deadlock in the project system with this commit - I don't think we need to do anything for RTM.

I still see the deadlock on the most recent d15rel builds. Am I missing something?

@mavasani
Copy link
Contributor Author

mavasani commented Feb 1, 2017

@dpoeschl - I also hit the deadlock right now when playing with MVC solution and attempting to close it(dotnet/project-system#1384)

 	mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext)	Unknown
 	mscorlib.dll!System.Threading.SemaphoreSlim.WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, System.Threading.CancellationToken cancellationToken)	Unknown
 	mscorlib.dll!System.Threading.SemaphoreSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)	Unknown
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnDocumentContextUpdated(Microsoft.CodeAnalysis.DocumentId documentId, Microsoft.CodeAnalysis.Text.SourceTextContainer container) Line 347	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnDocumentContextUpdated(Microsoft.CodeAnalysis.DocumentId documentId) Line 340	C#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.UpdateDocumentContextIfContainsDocument(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy sharedHierarchy, Microsoft.CodeAnalysis.DocumentId documentId) Line 953	C#
 	Microsoft.VisualStudio.LanguageServices.dll!Roslyn.VisualStudio.ProjectSystem.HierarchyEventsSink.OnPropertyChanged(uint itemid, int propid, uint flags) Line 31	C#
 	Microsoft.VisualStudio.ProjectSystem.Managed.VS.dll!Microsoft.VisualStudio.ProjectSystem.VS.LanguageServices.UnconfiguredProjectHostObject.OnPropertyChanged(uint itemid, int propid, uint flags) Line 98	C#
 	Microsoft.VisualStudio.ProjectSystem.Managed.VS.dll!Microsoft.VisualStudio.ProjectSystem.VS.LanguageServices.UnconfiguredProjectHostObject.SetProperty(uint itemid, int propid, object var) Line 77	C#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.SetDocumentContext(Microsoft.CodeAnalysis.DocumentId documentId) Line 912	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ClearOpenDocument(Microsoft.CodeAnalysis.DocumentId documentId, bool isSolutionClosing) Line 98	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ClearOpenDocuments(Microsoft.CodeAnalysis.ProjectId projectId) Line 77	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ClearProjectData(Microsoft.CodeAnalysis.ProjectId projectId) Line 260	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnProjectRemoved(Microsoft.CodeAnalysis.ProjectId projectId) Line 424	C#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.VisualStudioWorkspaceHost.Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.IVisualStudioWorkspaceHost.OnProjectRemoved(Microsoft.CodeAnalysis.ProjectId projectId) Line 1362	C#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.RemoveProject(Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject project) Line 322	C#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject.Disconnect() Line 1159	C#
 	Microsoft.VisualStudio.LanguageServices.Implementation.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS.CPSProject.Disconnect() Line 77	C#
 	Microsoft.VisualStudio.LanguageServices.Implementation.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS.CPSProject.Dispose() Line 222	C#
>	Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.LanguageServices.AggregateWorkspaceProjectContext.Dispose(System.Func<Microsoft.VisualStudio.LanguageServices.ProjectSystem.IWorkspaceProjectContext, bool> shouldDisposeInnerContext) Line 139	C#
 	Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.VS.LanguageServices.UnconfiguredProjectContextProvider.ReleaseProjectContextAsync(Microsoft.VisualStudio.ProjectSystem.LanguageServices.AggregateWorkspaceProjectContext context) Line 103	C#
 	Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.LanguageServices.LanguageServiceHost.DisposeCoreAsync(bool initialized) Line 288	C#

Seems like the workaround doesn't completely avoid it. Is it possible to put some defensive fix here?

@mavasani
Copy link
Contributor Author

mavasani commented Feb 1, 2017

In the new project system, when the solution is closing, the shared project hierarchy is still alive and functioning while the projects are being unloaded, which triggers hierarchy events and triggers OnDocumentContextUpdated, causing the deadlock.

@dpoeschl This is by design. For the new project system, we support cross targeting, so you can specify multiple target frameworks for your project. We create an AbstractProject for every target framework for the same underlying project (it likely has different references, sources, etc.) and they all have the same shared hierarchy based off the underlying VS project. When the user edits the TargetFrameworks property to add or remove frameworks, we dispose off the AbstractProject which are no longer in the TargetFrameworks, but the underlying VS project (shared hierarchy) still needs to be active. I had put a workaround in CPS that whenever we are disposing the AbstractProject(s), the underlying project queue's the SetProperty changed events and fires them after the Dispose is done - it seems to not be working for all cases.

dpoeschl pushed a commit to dpoeschl/roslyn that referenced this issue Feb 2, 2017
…a Solution close) referencing Shared Projects

Fixes dotnet#14479

The problem here is that unloading projects takes a serialization lock,
which can cause Shared Project IVsHierarchys to notify us that their
context hierarchy has changed. In response to this, we try to set the
new active context document for open files, which also tries to take the
serialization lock, and we deadlock.

For .NET Framework Projects that reference Shared Projects, two things
prevent deadlocks when projects unload. During solution close, any
Shared Projects are disconnected before the projects start to unload, so
no IVsHierarchy events are fired. During a single project unload, we
receive notification of the context hierarchy change before the project
is unloaded, avoiding any IVsHierarchy events if we tell the shared
hierarchy to set its context hierarchy to what it already is.

Neither of these behaviors are safe to rely on with .NET Standard
projects, so we have to prevent the deadlock ourselves. We do this by
remembering if we're already in the serialization lock due to project
unload, and then not take the lock to update document contexts if so
(but continuing to lock if it's not during a project unload).
@dpoeschl
Copy link
Contributor

dpoeschl commented Feb 3, 2017

@davkean @mavasani @srivatsn (FYI @Pilchie @mattwar): I still argue that the project system should be setting the new context hierarchy for shared projects before unloading the requested project. This used to be done in this stack:

Stack
>	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnDocumentContextUpdated(Microsoft.CodeAnalysis.DocumentId documentId, Microsoft.CodeAnalysis.Text.SourceTextContainer container) Line 347	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.OnDocumentContextUpdated(Microsoft.CodeAnalysis.DocumentId documentId) Line 338	C#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.UpdateDocumentContextIfContainsDocument(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy sharedHierarchy, Microsoft.CodeAnalysis.DocumentId documentId)	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Roslyn.VisualStudio.ProjectSystem.HierarchyEventsSink.OnPropertyChanged(uint itemid, int propid, uint flags)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.ProjectNode.OnPropertyChanged(uint itemId, int propid, uint flags)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.ImportingProjectsService.Microsoft.Internal.VisualStudio.Shell.Interop.IVsSharedMSBuildFilesEvents.OnAfterActiveContextForSharedMSBuildFileChanged(string sharedFileFullPath, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy oldActiveContextHierarchy, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy newActiveContextHierarchy)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.FireOnAfterActiveContextForSharedMSBuildFileChangedHelper(Microsoft.VisualStudio.Shell.EventSinkCollection eventSinkCollection, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy oldActiveContextHierarchy, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy newActiveContextHierarchy)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.FireOnAfterActiveContextChangedBody(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy oldActiveContextHierarchy, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy newActiveContextHierarchy)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.FireOnAfterActiveContextForSharedMSBuildFileChanged(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy oldActiveContextHierarchy, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy newActiveContextHierarchy, bool deferEventFiring)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.EnsureActiveContextIsValid(System.Tuple<Microsoft.VisualStudio.Shell.Interop.IVsHierarchy, System.Guid> newContextToChangeTo, bool reportIfNotValid, bool deferEventFiring)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.FireOnAfterSharedMSBuildFileUserClosed.AnonymousMethod__0()	Unknown
 	mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.(ref Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.<>c__DisplayClass109_0.<<FireOnAfterSharedMSBuildFileUserClosed>b__0>d stateMachine) Line 316	C#
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.FireOnAfterSharedMSBuildFileUserClosed.AnonymousMethod__0()	Unknown
 	Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTaskFactory.RunAsync(System.Func<System.Threading.Tasks.Task> asyncMethod, bool synchronouslyBlocking, Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions creationOptions, System.Delegate entrypointOverride) Line 532	C#
 	Microsoft.VisualStudio.ProjectSystem.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.ProjectMultiThreadedService.ExecuteSynchronously(System.Func<System.Threading.Tasks.Task> asyncAction)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.FireOnAfterSharedMSBuildFileUserClosed(System.Guid sharedFileUserProjectID, Microsoft.VisualStudio.ProjectSystem.RegistrationOption regOptions, bool unsubscribe)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode.UnregisterSharingProject(System.Guid sharedFileUserProjectID, bool unsubscribe)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileManagerHierarchy.UnregisterSharedFile(Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileNode sharedFileNode, System.Guid sharedFileUserProjectID, bool unsubscribe)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileManagerHierarchy.UnregisterAnySharedFiles(System.Guid sharedFileUserProjectID)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileManagerHierarchy.Microsoft.Internal.VisualStudio.Shell.Interop.IVsSharedMSBuildFilesManagerHierarchy.UnregisterAnySharedMSBuildFiles.AnonymousMethod__0()	Unknown
 	mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileManagerHierarchy.(ref Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileManagerHierarchy.<>c__DisplayClass94_0.<<Microsoft-Internal-VisualStudio-Shell-Interop-IVsSharedMSBuildFilesManagerHierarchy-UnregisterAnySharedMSBuildFiles>b__0>d stateMachine) Line 316	C#
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileManagerHierarchy.Microsoft.Internal.VisualStudio.Shell.Interop.IVsSharedMSBuildFilesManagerHierarchy.UnregisterAnySharedMSBuildFiles.AnonymousMethod__0()	Unknown
 	Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTaskFactory.RunAsync(System.Func<System.Threading.Tasks.Task> asyncMethod, bool synchronouslyBlocking, Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions creationOptions, System.Delegate entrypointOverride) Line 532	C#
 	Microsoft.VisualStudio.ProjectSystem.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.ProjectMultiThreadedService.ExecuteSynchronously(System.Func<System.Threading.Tasks.Task> asyncAction)	Unknown
 	Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.SharedProjectFilesPackage.SharedProjectFileManagerHierarchy.Microsoft.Internal.VisualStudio.Shell.Interop.IVsSharedMSBuildFilesManagerHierarchy.UnregisterAnySharedMSBuildFiles(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy sharedFileUserHierarchy)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.Internal.VisualStudio.PlatformUI.DataSource.Invoke(string verb, object pvaIn, out object pvaOut)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.VsCommand.Execute(object parameter)	Unknown
 	PresentationFramework.dll!MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(System.Windows.Input.ICommandSource commandSource, bool userInitiated) Line 197	C#
 	PresentationFramework.dll!System.Windows.Controls.MenuItem.InvokeClickAfterRender(object arg) Line 1419	C#
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 104	C#
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 37	C#
 	WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Line 583	C#
 	WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) Line 528	C#
 	WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Line 235	C#
 	mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 954	C#
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 902	C#
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 891	C#
 	WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 185	C#
 	WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Line 441	C#
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Line 2251	C#
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 2504	C#
 	WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 345	C#
 	WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Line 494	C#
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 104	C#
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 37	C#
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Line 1445	C#
 	WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Line 398	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.PushMessageLoopOnContextMenuTrackingComponent.AnonymousMethod__217_1(object sender, Microsoft.VisualStudio.PlatformUI.OleComponentSupport.PreTranslateMessageEventArgs args)	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.PlatformUI.OleComponentSupport.OleComponent.FPreTranslateMessageCore(Microsoft.VisualStudio.OLE.Interop.MSG[] pMsg)	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.PlatformUI.OleComponentSupport.OleComponent.Microsoft.VisualStudio.OLE.Interop.IOleComponent.FPreTranslateMessage.AnonymousMethod__0()	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.PlatformUI.OleComponentSupport.OleComponent.CallAndReturnOnException(System.Func<int> method, int retValueOnException)	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.PlatformUI.OleComponentSupport.OleComponent.Microsoft.VisualStudio.OLE.Interop.IOleComponent.FPreTranslateMessage(Microsoft.VisualStudio.OLE.Interop.MSG[] pMsg)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.PushMessageLoopOnContextMenuTrackingComponent()	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.Internal.VisualStudio.PlatformUI.HierarchyUtilities.ExecHierParentChain.AnonymousMethod__1()	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.ErrorHandler.CallWithCOMConvention(System.Func<int> method, bool reportError, bool setShellErrorInfo)	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.Internal.VisualStudio.PlatformUI.HierarchyUtilities.ExecHierParentChain(Microsoft.VisualStudio.Shell.IVsHierarchyItemManager manager, Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy lpUIHCmd, Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy lpUIHCurrent, uint itemidCurrent, ref System.Guid pguidCmdGroupRef, uint nCmdID, uint nCmdexecopt, System.IntPtr pvaIn, System.IntPtr pvaOut)	Unknown
 	Microsoft.VisualStudio.Shell.TreeNavigation.HierarchyProvider.dll!Microsoft.VisualStudio.PlatformUI.HierarchyItem.HierarchyContextMenuController.ShowContextMenu(System.Collections.Generic.IEnumerable<object> items, System.Windows.Point location)	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.Internal.VisualStudio.PlatformUI.ContextMenuController.ShowContextMenu(System.Collections.Generic.IEnumerable<Microsoft.Internal.VisualStudio.PlatformUI.IContextMenuPattern> items, System.Windows.Point location, System.Func<Microsoft.Internal.VisualStudio.PlatformUI.IContextMenuPattern, Microsoft.Internal.VisualStudio.PlatformUI.IContextMenuController> getController)	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.Internal.VisualStudio.PlatformUI.ContextMenuController.ShowContextMenu(System.Collections.Generic.IEnumerable<Microsoft.Internal.VisualStudio.PlatformUI.IContextMenuPattern> items, System.Windows.Point location)	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.Internal.VisualStudio.PlatformUI.PivotTreeView.OnContextMenuOpening(System.Windows.Controls.ContextMenuEventArgs e)	Unknown
 	PresentationFramework.dll!System.Windows.FrameworkElement.OnContextMenuOpeningThunk(object sender, System.Windows.Controls.ContextMenuEventArgs e) Line 6018	C#
 	PresentationFramework.dll!System.Windows.Controls.ContextMenuEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Line 548	C#
 	PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Line 341	C#
 	PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Line 81	C#
 	PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Line 205	C#
 	PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Line 2354	C#
 	PresentationCore.dll!System.Windows.ContentElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) Line 478	C#
 	PresentationCore.dll!System.Windows.ContentElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted) Line 459	C#
 	PresentationFramework.dll!System.Windows.Controls.PopupControlService.RaiseContextMenuOpeningEvent(System.Windows.IInputElement source, double x, double y, bool userInitiated) Line 705	C#
 	PresentationFramework.dll!System.Windows.Controls.PopupControlService.ProcessMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) Line 182	C#
 	PresentationFramework.dll!System.Windows.Controls.PopupControlService.OnPostProcessInput(object sender, System.Windows.Input.ProcessInputEventArgs e) Line 147	C#
 	PresentationCore.dll!System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(System.Windows.Input.ProcessInputEventHandler postProcessInput, System.Windows.Input.ProcessInputEventArgs processInputEventArgs) Line 1113	C#
 	PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Line 1061	C#
 	PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Line 710	C#
 	PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) Line 126	C#
 	PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) Line 1385	C#
 	PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 617	C#
 	PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 1768	C#
 	WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 345	C#
 	WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Line 494	C#
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 104	C#
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 37	C#
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Line 1445	C#
 	WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Line 398	C#

Roslyn currently only triggers the context change notification to the hierarchy if there are open documents from the shared project (the very thing that's causing the hang). So we still have a gap here even with my proposed deadlock avoidance "fix", when there are no open documents.

If CPS can set the new context hierarchy itself, then I can completely avoid the reentrancy problem instead of hackily work around it. I don't think the Roslyn Workspace should be responsible for updating this. Is this particular new behavior "by design" for some reason?

@mattwar
Copy link
Contributor

mattwar commented Feb 3, 2017

Workspace.ClearProjectData should not be doing anything but cleaning up additional dictionaries/collections that the individual implementation may be keeping around. Nothing should be causing events to fire here. This code is called under the state lock. It should not call into arbitrary code.

@miloush
Copy link

miloush commented Feb 7, 2017

Is this meant to be closed?

@mavasani
Copy link
Contributor Author

mavasani commented Feb 7, 2017

@mattwar @dpoeschl do we want to re-activate this to track the correct post RTM fix for the deadlock?

@davkean
Copy link
Member

davkean commented Mar 23, 2018

This looks like it was accidently closed. Looking at our code on our side and we got a large complicated way of avoiding this deadlock. We shouldn't be calling this under a lock, @jasonmalinowski can put this on radar as you change this code?

@davkean
Copy link
Member

davkean commented Mar 23, 2018

Sorry, looking back at this - looks like @dpoeschl actually made the right change #16889 as per your suggestion - @mavasani you made a comment after that indicating that might be incorrect change. Can you confirm?

@mavasani
Copy link
Contributor Author

I believe @dpoeschl also made a follow up change #17372. I believe we should now not be hitting the original deadlock. We can probably delete the workaround in project system to get around this issue.

@jasonmalinowski
Copy link
Member

OK, state here is confusing. I do know @dpoeschl made a change here as observed. And we can make that better. So what's the ask here for me? Don't regress this? 😄

@davkean
Copy link
Member

davkean commented Mar 26, 2018

I'm thinking this is now fixed and going to assume it is as I change our workaround on our side.

@davkean davkean closed this as completed Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner.
Projects
None yet
8 participants