Skip to content

Only subscribe to AppDomain.AssemblyResolve once#53166

Open
jasonmalinowski wants to merge 1 commit intodotnet:mainfrom
jasonmalinowski:fix-appdomain-hook
Open

Only subscribe to AppDomain.AssemblyResolve once#53166
jasonmalinowski wants to merge 1 commit intodotnet:mainfrom
jasonmalinowski:fix-appdomain-hook

Conversation

@jasonmalinowski
Copy link
Copy Markdown
Member

No description provided.

@jasonmalinowski jasonmalinowski requested a review from a team as a code owner May 5, 2021 03:34
@ghost ghost added the Area-Analyzers label May 5, 2021
@jasonmalinowski jasonmalinowski self-assigned this May 5, 2021
protected override Assembly LoadFromPathImpl(string fullPath)
{
if (Interlocked.CompareExchange(ref _hookedAssemblyResolve, 0, 1) == 0)
if (Interlocked.CompareExchange(ref _hookedAssemblyResolve, value: 1, comparand: 0) == 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have any tests in this area?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll see what I can find. Even if we did, unless the test explicitly asserted the value of the field we probably wouldn't have noticed: since AssemblyResolve stops calling further handlers after one gives a successful resolution, the extra ones just aren't called. So this is really only a memory leak given we might subscribe n times instead of 1 time, but the n is somewhat bounded by the number of analyzers loaded in the process.

jasonmalinowski added a commit to jasonmalinowski/omnisharp-roslyn that referenced this pull request May 5, 2021
This is a port of dotnet/roslyn#53166. There's a
bigger question here about how to reuse this code better, but this
caused a bunch of confusion while debugging an issue.
@JoeRobich
Copy link
Copy Markdown
Member

Changing target branch to 16.11 servicing branch

@JoeRobich JoeRobich changed the base branch from release/dev16.11 to release/dev16.11-vs-deps August 16, 2021 20:14
@jasonmalinowski jasonmalinowski changed the base branch from release/dev16.11-vs-deps to main September 1, 2021 00:34
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@jasonmalinowski can we take this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants