dyn-metrics-store: fix race on StatsCounter use_count#858
Merged
MrAnno merged 4 commits intoaxoflow:mainfrom Nov 26, 2025
Merged
dyn-metrics-store: fix race on StatsCounter use_count#858MrAnno merged 4 commits intoaxoflow:mainfrom
MrAnno merged 4 commits intoaxoflow:mainfrom
Conversation
`use_count` is a non-atomic integer. Modifying it from parallel threads at the same time is racy. Both `merge()` and `retrieve_counter()` increases the `use_count` of a counter. - `merge()` is called with the `global_metrics_cache_lock` held - `retrieve_counter()` calls `stats_lock()` inside If `merge()` is being called in one thread (thread deinit) and `retrieve_counter()` is being called in another (new counter for the TLS cache), they can run in the same time, incrementing `use_count` in a racy manner. Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
MrAnno
approved these changes
Nov 26, 2025
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
use_countis a non-atomic integer.Modifying it from parallel threads at the same time is racy.
Both
merge()andretrieve_counter()increases theuse_countof a counter.merge()is called with theglobal_metrics_cache_lockheldretrieve_counter()callsstats_lock()insideThese are two different locks, and don't block each other.
If
merge()is being called in one thread (thread deinit) andretrieve_counter()is being called in another (new counter for the TLS cache), they can run in the same time, incrementinguse_countin a racy manner.