From 658c79e1d50d19b461da6528884372d1c01de6ad Mon Sep 17 00:00:00 2001 From: Diego Augusto Molina Date: Wed, 2 Oct 2024 07:30:44 -0300 Subject: [PATCH] Chore: fix initialization data race in infra usagestats (#94070) fix initialization data race in usagestats --- pkg/infra/usagestats/service/service.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/infra/usagestats/service/service.go b/pkg/infra/usagestats/service/service.go index ccd9357fb56..8974a3286ae 100644 --- a/pkg/infra/usagestats/service/service.go +++ b/pkg/infra/usagestats/service/service.go @@ -3,6 +3,7 @@ package service import ( "context" "encoding/json" + "sync/atomic" "time" "github.com/grafana/grafana/pkg/api/routing" @@ -27,7 +28,7 @@ type UsageStats struct { externalMetrics []usagestats.MetricsFunc sendReportCallbacks []usagestats.SendReportCallbackFunc - readyToReport bool + readyToReport atomic.Bool } func ProvideService(cfg *setting.Cfg, @@ -79,7 +80,7 @@ func (uss *UsageStats) Run(ctx context.Context) error { for { select { case <-sendReportTicker.C: - if !uss.readyToReport { + if !uss.readyToReport.Load() { nextSendInterval = time.Minute sendReportTicker.Reset(nextSendInterval) continue @@ -114,7 +115,7 @@ func (uss *UsageStats) RegisterSendReportCallback(c usagestats.SendReportCallbac func (uss *UsageStats) SetReadyToReport(context.Context) { uss.log.Info("Usage stats are ready to report") - uss.readyToReport = true + uss.readyToReport.Store(true) } func (uss *UsageStats) supportBundleCollector() supportbundles.Collector {