From 438680636d24c3014bcfba0ff32f8da0b3b0e723 Mon Sep 17 00:00:00 2001 From: Lukas Jenicek Date: Thu, 21 Mar 2024 20:34:48 +0100 Subject: [PATCH] prevent race condition when reading from counters slice (#247) --- scope_registry.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scope_registry.go b/scope_registry.go index fc1b50b..57904c0 100644 --- a/scope_registry.go +++ b/scope_registry.go @@ -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)