Skip to content

dyn-metrics-store: fix race on StatsCounter use_count#858

Merged
MrAnno merged 4 commits intoaxoflow:mainfrom
alltilla:fix-dyn-metrics-store-race
Nov 26, 2025
Merged

dyn-metrics-store: fix race on StatsCounter use_count#858
MrAnno merged 4 commits intoaxoflow:mainfrom
alltilla:fix-dyn-metrics-store-race

Conversation

@alltilla
Copy link
Member

@alltilla alltilla commented Nov 25, 2025

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

These are two different locks, and don't block each other.

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.

`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]>
@alltilla alltilla requested a review from MrAnno November 25, 2025 16:08
@MrAnno MrAnno merged commit a0f9d2b into axoflow:main Nov 26, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants