Skip to content

Fix ThreadLocal tracking behavior - #56956

Merged
davidwrighton merged 1 commit into
dotnet:mainfrom
davidwrighton:fix_threadlocal_tracking
Aug 10, 2021
Merged

davidwrighton merged 1 commit into
dotnet:mainfrom
davidwrighton:fix_threadlocal_tracking

Conversation

@davidwrighton

Copy link
Copy Markdown
Member
  • Before this change the trackAllValues behavior for ThreadLocal was defined by the first instance of thread local to have its value set on the thread
    • This could lead to unpredictable memory leaks (where the value was improperly tracked even though it wasn't supposed to be) This reproduces as a memory leak with no other observable behavior
    • Or data loss, where the Values collection was missing entries.
  • Change the model so that ThreadLocal trackAllValues behavior is properly defined by the exact ThreadLocal instance in use
  • Implement by keeping track of the track all changes behavior within the IdManager

Fixes #55796

- Before this change the trackAllValues behavior for ThreadLocal<SomeParticularType> was defined by the first instance of thread local to have its value set on the thread
  - This could lead to unpredictable memory leaks (where the value was improperly tracked even though it wasn't supposed to be) This reproduces as a memory leak with no other observable behavior
  - Or data loss, where the Values collection was missing entries.
- Change the model so that ThreadLocal<T> trackAllValues behavior is properly defined by the exact ThreadLocal<T> instance in use
- Implement by keeping track of the track all changes behavior within the IdManager

Fixes dotnet#55796
@ghost

ghost commented Aug 6, 2021

Copy link
Copy Markdown

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Issue Details
  • Before this change the trackAllValues behavior for ThreadLocal was defined by the first instance of thread local to have its value set on the thread
    • This could lead to unpredictable memory leaks (where the value was improperly tracked even though it wasn't supposed to be) This reproduces as a memory leak with no other observable behavior
    • Or data loss, where the Values collection was missing entries.
  • Change the model so that ThreadLocal trackAllValues behavior is properly defined by the exact ThreadLocal instance in use
  • Implement by keeping track of the track all changes behavior within the IdManager

Fixes #55796

Author: davidwrighton
Assignees: -
Labels:

area-System.Threading

Milestone: -

@davidwrighton
davidwrighton requested a review from kouvel August 6, 2021 02:30

@kouvel kouvel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thank you!

@davidwrighton
davidwrighton merged commit fc2c089 into dotnet:main Aug 10, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 9, 2021
@davidwrighton
davidwrighton deleted the fix_threadlocal_tracking branch April 13, 2023 18:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ThreadLocals of the same type T can interfere with each other's trackAllValues

2 participants