Skip to content

Commit

Permalink
fix: use Lock instead of RLock to prevent a possible race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
d-Rickyy-b committed Aug 7, 2024
1 parent cd4aaef commit b234e22
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/certificatetransparency/logmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func (m *LogMetrics) Init(operator, url string) {

// Get the metric for a given operator and ct url.
func (m *LogMetrics) Get(operator, url string) int64 {
m.mutex.RLock()
defer m.mutex.RUnlock()
// 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.
m.mutex.Lock()
defer m.mutex.Unlock()

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

0 comments on commit b234e22

Please sign in to comment.