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

AssemblyList throws LockRecursionException #627

Closed
Cronan opened this issue Feb 13, 2018 · 4 comments · Fixed by #628
Closed

AssemblyList throws LockRecursionException #627

Cronan opened this issue Feb 13, 2018 · 4 comments · Fixed by #628
Assignees

Comments

@Cronan
Copy link
Contributor

Cronan commented Feb 13, 2018

Environment

  • Pythonnet version: djoyce82's core_clr candidate
  • Python version: 2.7
  • Operating System: Red Hat Linux

Details

Use Nuget to obtain the System.Configuration.ConfigurationManager package:

<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />

then:

    from System.Configuration import ConfigurationManager

The code then throws a LockRecursionException in AssemblyList.GetEnumerator(), caused by EnterReadLock() when another lock is already held.

This is probably caused by the fact that System.Configuration and System.Configuration.ConfigurationManager are both assemblies that need to be loaded, and there is a race condition between the AssemblyLoadHandler, the ResolveHandler, LookupType and FindLoadedAssembly.

@Cronan
Copy link
Contributor Author

Cronan commented Feb 13, 2018

I was able to fix this by replacing the AssemblyList implementation with:

private static ConcurrentBag<Assembly> assemblies;

and a constructor:

assemblies = new ConcurrentBag<Assembly>();

@den-run-ai
Copy link
Contributor

@Cronan pull requests are welcome :) thanks for finding this! I wonder if there is the same lock recursion in other .NET runtimes?

@Cronan
Copy link
Contributor Author

Cronan commented Feb 13, 2018

@denfromufa A PR is in the wings, but I wasn't sure whether there was too much going on at the moment?

I'll see if I can get the same thing to happen in other runtimes with a "fake" example - I think the naming of System.Configuration and System.Configuration.ConfigurationManager is significant, as is the fact that the second uses types from the first ...

Not so easy to put this into the tests, I think, it needs two assemblies ...

Please assign it to me, I'll get a PR out soon, hopefully with a covering test.

@den-run-ai
Copy link
Contributor

den-run-ai commented Feb 13, 2018

@Cronan this PR is small enough to be merged without much effort. Some PRs are not like that.

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 a pull request may close this issue.

2 participants