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

Gate the construction of the singleton RemoteWorkspace #43370

Merged
merged 2 commits into from
Apr 15, 2020

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Apr 15, 2020

Workspace.Dispose() doesn't dispose of all the workspace and language services it provides. For items that export IWorkspaceService or ILanguageService directly, this isn't a problem because those instances are serviced by the underlying MEF catalog and it will dispose of items. However, for items provided by IWorkspaceServiceFactory, only the factory is tracked by the underlying MEF catalog and the factory-created instances are part of each workspace. For unit tests, we're good about making sure both the workspace and the MEF catalog are disposed. However, for integration tests things are a bit more relaxed. In devenv.exe, we only have one Workspace and one MEF catalog and neither get disposed until VS is shutting down. For the OOP process, however, we have some paths by which more than one RemoteWorkspace can get created, and these are not disposed. If more than one RemoteWorkspace instance gets created, one of them will be discarded, which can lead to finalization of SqlConnection if the discarded workspace performed any database operations. This is an attempt to fix the issue by putting a lock around the new RemoteWorkspace() call in SolutionService.PrimaryWorkspace.

In addition, two cases in test code where IPersistentStorage was not disposed have been corrected.

Fixes #22302

@sharwell sharwell marked this pull request as ready for review April 15, 2020 15:42
@sharwell sharwell requested review from a team as code owners April 15, 2020 15:42
@sharwell sharwell merged commit 9e48ecf into dotnet:master Apr 15, 2020
@ghost ghost added this to the Next milestone Apr 15, 2020
@sharwell sharwell deleted the remote-workspace branch April 15, 2020 18:37
Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Good catch!

_ = new RemoteWorkspace();
lock (s_remoteWorkspaceGate)
{
if (primaryWorkspace.Workspace is null)
Copy link
Member

Choose a reason for hiding this comment

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

we used == above, and is here :'(

Copy link
Member

Choose a reason for hiding this comment

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

is null FTW 😄

@CyrusNajmabadi
Copy link
Member

So now i'm sad. Because this does indicate that the Finalizer was working (in that it notified us that someone was doing something bad)...

@sharwell sharwell modified the milestones: Next, temp, 16.7.P1 Apr 28, 2020
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.

SqlConnection.Finalize can cause crashes
6 participants