Uh oh!
There was an error while loading. Please reload this page.
Avoid clearing thread local handles for already unloaded LoaderAllocator - #102797
Conversation
…collectible LoaderAllocators
alexey-zakharov
commented
May 29, 2024
@jkotas@davidwrighton checks are green for this PR |
Tagging subscribers to this area: @mangod9 |
jkotas
commented
May 29, 2024
/azp run runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
jkotas
commented
May 29, 2024
/backport to release/8.0-staging |
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/9293876461 |
@jkotas backporting to release/8.0-staging failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Ensure LoaderAllocator can't be collected while we clean handles on collectible LoaderAllocatorsUsing index info to reconstruct a base tree...M src/coreclr/vm/threadstatics.cppFalling back to patching base and 3-way merge...Auto-merging src/coreclr/vm/threadstatics.cppCONFLICT (content): Merge conflict in src/coreclr/vm/threadstatics.cpperror: Failed to merge in the changes.hint: Use 'git am --show-current-patch=diff' to see the failed patchhint: When you have resolved this problem, run "git am --continue".hint: If you prefer to skip this patch, run "git am --skip" instead.hint: To restore the original branch and stop patching, run "git am --abort".hint: Disable this message with "git config advice.mergeConflict false"Patch failed at 0001 Ensure LoaderAllocator can't be collected while we clean handles on collectible LoaderAllocators
Error: The process '/usr/bin/git' failed with exit code 128Please backport manually! |
@jkotas an error occurred while backporting to release/8.0-staging, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
jkotas
commented
May 29, 2024
@alexey-zakharov If you would like to see this backported to .NET 8, could you please submit a PR against release/8.0-staging branch with the merge conflicts resolved? |
alexey-zakharov
commented
May 30, 2024
…collectible LoaderAllocators (dotnet#102797)
Motivation:
Fix crash in
ThreadLocalBlock::FreeTLMcode on thread exit which happens during Assembly unloading when Assembly contains a class with aThreadStaticvariable.This is a new iteration of #99998 which caused issues on CI.
Details:
There seem to be a race condition between LoaderAllocator cleanup during garbage collection and thread locals cleanup on thread exit. Racing stacks are the following:
ALC/LoaderAllocator cleanup
Thread exit with threadlocal cleanup
with an exception which is thrown with the following details:
loaderAllocatorvalue from theLOADERALLOCATORREF loaderAllocator = (LOADERALLOCATORREF)ObjectFromHandle(m_hLoaderAllocatorObjectHandle);call is NULL which makes sense, because finalizer thread just disposed data for some of the same LoaderAllocator assemblies.Note: enabling
COR_PRF_MONITOR_MODULE_LOADSCLR profiler flag increases chances for the race condition as it slows down a bit complete loader destruction.Changes:
I've looked at the following options as a solution to the problem:
loaderAllocatorBased on the discussion the acceptable solution would be to: