From 0ee99fd21494ccbec755965b221296c1124e4fc0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 1 Nov 2021 14:51:25 +0200 Subject: [PATCH] set.go: fix data race in Set.ListMetricNames when accessing Set.m map The Set.m map can be updated by concurrent goroutines when ListMetricNames is called --- set.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/set.go b/set.go index 69b4de8..ae55bb7 100644 --- a/set.go +++ b/set.go @@ -511,6 +511,8 @@ func (s *Set) UnregisterMetric(name string) bool { // ListMetricNames returns a list of all the metrics in s. func (s *Set) ListMetricNames() []string { + s.mu.Lock() + defer s.mu.Unlock() var list []string for name := range s.m { list = append(list, name)