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

Fix race condition in cleanup of collectible thread static variables #111257

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

davidwrighton
Copy link
Member

There was a race condition where we could have collected all of the managed state of a LoaderAllocator, but not yet started cleaning up the actual LoaderAllocator object in native code. If a thread which had a TLS variable defined in a code associated with a collectible loader allocator was terminated at that point, then the runtime would crash.

The fix is to detect if the LoaderAllocator managed state is still alive, and if so, do not attempt to clean it up.

Attached is a test case which is a reduced version of a stress test used to examine the issue

Fixes #110837

There was a race condition where we could have collected all of the managed state of a LoaderAllocator, but not yet started cleaning up the actual LoaderAllocator object in native code. If a thread which had a TLS variable defined in a code associated with a collectible loader allocator was terminated at that point, then the runtime would crash.

The fix is to detect if the LoaderAllocator managed state is still alive, and if so, do not attempt to clean it up.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 4 changed files in this pull request and generated 2 comments.

Files not reviewed (3)
  • src/coreclr/vm/threadstatics.cpp: Language not supported
  • src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.csproj: Language not supported
  • src/tests/issues.targets: Language not supported
Comments suppressed due to low confidence (3)

src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.cs:16

  • [nitpick] The variable name 'UseTLSStaticFromLoaderAllocator' is long and not very descriptive. Consider renaming it to something more concise and descriptive.
Action? UseTLSStaticFromLoaderAllocator = null;

src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.cs:17

  • [nitpick] The variable name 'IsLoaderAllocatorLive' suggests a boolean, but it is a GCHandle. Consider renaming it to something more appropriate, like 'loaderAllocatorHandle'.
GCHandle IsLoaderAllocatorLive;

src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.cs:96

  • The test method 'TestEntryPoint' does not assert any conditions. It should include assertions to verify the expected behavior.
[Fact]
public static void TestEntryPoint()

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.

Internal CLR error. (0x80131506) in threads.cpp
2 participants