Skip to content

Commit

Permalink
prevent race condition when reading from counters slice (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek authored Mar 21, 2024
1 parent e2a71ea commit 4386806
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scope_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ func (r *scopeRegistry) reportInternalMetrics() {
scopes.Inc() // Account for root scope.
r.ForEachScope(
func(ss *scope) {
ss.cm.RLock()
defer ss.cm.RUnlock()
counterSliceLen, gaugeSliceLen, histogramSliceLen := int64(len(ss.countersSlice)), int64(len(ss.gaugesSlice)), int64(len(ss.histogramsSlice))
if ss.root { // Root scope is referenced across all buckets.
rootCounters.Store(counterSliceLen)
Expand Down

0 comments on commit 4386806

Please sign in to comment.