satellite/repair: protect concurrent access to statsCollector
It would appear that we have been making concurrent accesses to statsCollector for a long, long time (we expect there to be multiple calls to `Repair()` at the same time on the same instance of `SegmentRepairer`, up to `config.MaxRepair`, and before this change there was no sort of synchronization guarding accesses to the `statsCollector.stats` map. Refs: https://github.com/storj/storj/issues/6402 Change-Id: I5bcdd13c88913a8d66f6dd906c9037c588960cc9
This commit is contained in:
parent
7381b5e508
commit
ee33cb1289
@ -5,6 +5,7 @@ package repairer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/spacemonkeygo/monkit/v3"
|
||||
)
|
||||
@ -13,6 +14,7 @@ import (
|
||||
// seen by the repairer. These are chained into the monkit scope for
|
||||
// monitoring as they are initialized.
|
||||
type statsCollector struct {
|
||||
lock sync.Mutex
|
||||
stats map[string]*stats
|
||||
}
|
||||
|
||||
@ -23,6 +25,9 @@ func newStatsCollector() *statsCollector {
|
||||
}
|
||||
|
||||
func (collector *statsCollector) getStatsByRS(rs string) *stats {
|
||||
collector.lock.Lock()
|
||||
defer collector.lock.Unlock()
|
||||
|
||||
stats, ok := collector.stats[rs]
|
||||
if !ok {
|
||||
stats = newStats(rs)
|
||||
|
Loading…
Reference in New Issue
Block a user