accounting: fix race stopping/starting the stats counter
Some checks are pending
Docker beta build / Build image job (push) Waiting to run

This was picked up by the race detector in the CI.
This commit is contained in:
Nick Craig-Wood 2025-01-11 20:23:41 +00:00
parent 101dcfe157
commit a7db375f5d

View File

@ -360,8 +360,8 @@ func (s *StatsInfo) averageLoop() {
// Start the average loop
func (s *StatsInfo) startAverageLoop() {
s.mu.RLock()
defer s.mu.RUnlock()
s.mu.Lock()
defer s.mu.Unlock()
s.average.startOnce.Do(func() {
s.average.stopped.Add(1)
go s.averageLoop()
@ -380,8 +380,8 @@ func (s *StatsInfo) _stopAverageLoop() {
// Stop the average loop
func (s *StatsInfo) stopAverageLoop() {
s.mu.RLock()
defer s.mu.RUnlock()
s.mu.Lock()
defer s.mu.Unlock()
s._stopAverageLoop()
}