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
This commit is contained in:
parent
2ec4485cad
commit
0ee99fd214
2
set.go
2
set.go
@ -511,6 +511,8 @@ func (s *Set) UnregisterMetric(name string) bool {
|
|||||||
|
|
||||||
// ListMetricNames returns a list of all the metrics in s.
|
// ListMetricNames returns a list of all the metrics in s.
|
||||||
func (s *Set) ListMetricNames() []string {
|
func (s *Set) ListMetricNames() []string {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
var list []string
|
var list []string
|
||||||
for name := range s.m {
|
for name := range s.m {
|
||||||
list = append(list, name)
|
list = append(list, name)
|
||||||
|
Loading…
Reference in New Issue
Block a user