Skip to content

Commit 670e785

Browse files
gqcngitperr
authored andcommitted
fix: data race of NetClassCollector metrics initialization when multiple requests happen (prometheus#2995)
Signed-off-by: John Guo <[email protected]>
1 parent 28355a3 commit 670e785

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

collector/netclass_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net"
2323
"os"
2424
"regexp"
25+
"sync"
2526

2627
"github.com/alecthomas/kingpin/v2"
2728
"github.com/go-kit/log"
@@ -41,6 +42,7 @@ type netClassCollector struct {
4142
subsystem string
4243
ignoredDevicesPattern *regexp.Regexp
4344
metricDescs map[string]*prometheus.Desc
45+
metricDescsMu sync.Mutex
4446
logger log.Logger
4547
}
4648

@@ -136,6 +138,9 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err
136138
}
137139

138140
func (c *netClassCollector) getFieldDesc(name string) *prometheus.Desc {
141+
c.metricDescsMu.Lock()
142+
defer c.metricDescsMu.Unlock()
143+
139144
fieldDesc, exists := c.metricDescs[name]
140145

141146
if !exists {

0 commit comments

Comments
 (0)