-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix unloadability issue in AppDomain::FindAssembly #58948
Conversation
There is a bug in AppDomain::FindAssembly code path that iterates over the domain assemblies. The iteration loop leaves the refcount of the LoaderAllocator related to the returned DomainAssembly bumped, but nothing ever decrements it. So when a code that needs to be unloaded ends up in that code path, all the managed things like managed LoaderAllocator, LoaderAllocatorScout are destroyed, but the unloading doesn't complete due to the refcount. We have never found it before as this code path is never executed in any of the coreclr tests even with unloadability testing option.
@janvorli We're currently examining the risk for backporting #61266 (comment) and trying to decide if the value is worth it. It sounds like without this change, the XmlSerializer DLLs wouldn't be unloadable. If we were to bring this change back too, what would the risk look like? |
@agocke it is kind of hard to asses the risk here, even though I believe this was wrong before and the fix should not introduce any failure modes. But none of our coreclr or libraries tests execute this code path, so the only testing that was done was using the unload of the XmlSerializer where the unload was consistently failing before this fix and I believe it is consistently succeeding after the fix. |
@agocke and @janvorli, has there been any more conversation around porting this back to 6.0? We do have customers who have been asking for quite some time for the XmlSerializer fix that tripped on this, and they have noticed it isn't in .Net 6 yet. While I do think there is value in the XmlSerializer fix on it's own, as it enables an experience that is less broken than the previous 'can't do this at all' story... having this fix in 6.0 would really be helpful, especially since 6.0 is LTS. |
I think it is to fine to ship this fix in 6.0 servicing, but I would like to see us to gain more confidence in the fix as part of it, e.g. create a small regression test that hits the bug and demonstrates that the bug is fixed with this change. |
There is a bug in AppDomain::FindAssembly code path that iterates over
the domain assemblies. The iteration loop leaves the refcount of the
LoaderAllocator related to the returned DomainAssembly bumped, but
nothing ever decrements it. So when a code that needs to be unloaded
ends up in that code path, all the managed things like managed
LoaderAllocator, LoaderAllocatorScout are destroyed, but the unloading
doesn't complete due to the refcount.
We have never found it before as this code path is never executed in any
of the coreclr tests even with unloadability testing option.
The problem was reported yesterday by @StephenMolloy who has found
it when working on making Xml serializer behave with unloadability.