Skip to content

Commit b234e22

Browse files
committed
fix: use Lock instead of RLock to prevent a possible race condition
1 parent cd4aaef commit b234e22

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

internal/certificatetransparency/logmetrics.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ func (m *LogMetrics) Init(operator, url string) {
8080

8181
// Get the metric for a given operator and ct url.
8282
func (m *LogMetrics) Get(operator, url string) int64 {
83-
m.mutex.RLock()
84-
defer m.mutex.RUnlock()
83+
// Despite this being a getter, we still need to fully lock the mutex because we might modify the map if the requested operator does not exist.
84+
m.mutex.Lock()
85+
defer m.mutex.Unlock()
8586

8687
if _, ok := m.metrics[operator]; !ok {
8788
m.metrics[operator] = make(OperatorMetric)

0 commit comments

Comments
 (0)