-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
base: main
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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()
src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.cs
Outdated
Show resolved
Hide resolved
src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.cs
Outdated
Show resolved
Hide resolved
…taticCollection.cs Co-authored-by: Copilot <[email protected]>
…taticCollection.cs Co-authored-by: Copilot <[email protected]>
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