From b234e2280dfb687af8d0c724f24e9faa03dddc22 Mon Sep 17 00:00:00 2001 From: Rico Date: Thu, 8 Aug 2024 01:39:11 +0200 Subject: [PATCH] fix: use Lock instead of RLock to prevent a possible race condition --- internal/certificatetransparency/logmetrics.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/certificatetransparency/logmetrics.go b/internal/certificatetransparency/logmetrics.go index 89d9327..b47e055 100644 --- a/internal/certificatetransparency/logmetrics.go +++ b/internal/certificatetransparency/logmetrics.go @@ -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)