Fix race condition in cleanup of collectible thread static variables#111257
Merged
davidwrighton merged 5 commits intodotnet:mainfrom Jan 10, 2025
Merged
Fix race condition in cleanup of collectible thread static variables#111257davidwrighton merged 5 commits intodotnet:mainfrom
davidwrighton merged 5 commits intodotnet:mainfrom
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.
Contributor
There was a problem hiding this comment.
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]>
jkotas
approved these changes
Jan 9, 2025
3 tasks
Member
Author
|
/backport to release/9.0-staging |
Contributor
|
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/12712153173 |
Merged
4 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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