fix(scanner): resolve data race on conf.Server access in getScanner
Captured DevExternalScanner config value in the controller struct at construction time instead of reading the global conf.Server pointer in getScanner(). The background goroutine spawned by ScanFolders() was reading conf.Server.DevExternalScanner concurrently with test cleanup reassigning the conf.Server pointer, causing a data race detected by the race detector in the E2E test suite.
This commit is contained in:
@@ -35,15 +35,16 @@ func New(rootCtx context.Context, ds model.DataStore, cw artwork.CacheWarmer, br
|
||||
broker: broker,
|
||||
pls: pls,
|
||||
metrics: m,
|
||||
devExternalScanner: conf.Server.DevExternalScanner,
|
||||
}
|
||||
if !conf.Server.DevExternalScanner {
|
||||
if !c.devExternalScanner {
|
||||
c.limiter = P(rate.Sometimes{Interval: conf.Server.DevActivityPanelUpdateRate})
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (s *controller) getScanner() scanner {
|
||||
if conf.Server.DevExternalScanner {
|
||||
if s.devExternalScanner {
|
||||
return &scannerExternal{}
|
||||
}
|
||||
return &scannerImpl{ds: s.ds, cw: s.cw, pls: s.pls}
|
||||
@@ -99,6 +100,7 @@ type controller struct {
|
||||
metrics metrics.Metrics
|
||||
pls core.Playlists
|
||||
limiter *rate.Sometimes
|
||||
devExternalScanner bool
|
||||
count atomic.Uint32
|
||||
folderCount atomic.Uint32
|
||||
changesDetected bool
|
||||
|
||||
Reference in New Issue
Block a user