fix(filterlists): Resolve occasional FilterLists initialization failures
Improved module initialization and processing logic to enhance concurrency handling and ensure reliable https://github.com/safing/portmaster/issues/1951
This commit is contained in:
@@ -110,6 +110,7 @@ func processListFile(ctx context.Context, filter *scopedBloom, file *updates.Art
|
||||
})
|
||||
}
|
||||
|
||||
// Decode file and send entries to values channel.
|
||||
startSafe(func() (err error) {
|
||||
defer close(values)
|
||||
|
||||
@@ -117,6 +118,15 @@ func processListFile(ctx context.Context, filter *scopedBloom, file *updates.Art
|
||||
return
|
||||
})
|
||||
|
||||
// Wait for the module initialization to complete to ensure the filter is fully loaded.
|
||||
// This avoids prolonged locks during filter updates caused by concurrent database loading.
|
||||
select {
|
||||
case <-moduleInitDone:
|
||||
case <-time.After(time.Second * 20):
|
||||
log.Warning("intel/filterlists: timeout waiting for module initialization")
|
||||
}
|
||||
|
||||
// Process each entry and send records to records channel.
|
||||
startSafe(func() error {
|
||||
defer close(records)
|
||||
for entry := range values {
|
||||
@@ -128,6 +138,7 @@ func processListFile(ctx context.Context, filter *scopedBloom, file *updates.Art
|
||||
return nil
|
||||
})
|
||||
|
||||
// Persist records to the database.
|
||||
persistRecords(startSafe, records)
|
||||
|
||||
return g.Wait()
|
||||
|
||||
@@ -45,14 +45,17 @@ func (fl *FilterLists) Stop() error {
|
||||
return stop()
|
||||
}
|
||||
|
||||
// booleans mainly used to decouple the module
|
||||
// during testing.
|
||||
var (
|
||||
moduleInitDone chan struct{}
|
||||
|
||||
// booleans mainly used to decouple the module during testing.
|
||||
ignoreUpdateEvents = abool.New()
|
||||
ignoreNetEnvEvents = abool.New()
|
||||
)
|
||||
|
||||
func init() {
|
||||
moduleInitDone = make(chan struct{})
|
||||
|
||||
ignoreNetEnvEvents.Set()
|
||||
}
|
||||
|
||||
@@ -87,6 +90,10 @@ func start() error {
|
||||
filterListLock.Lock()
|
||||
defer filterListLock.Unlock()
|
||||
|
||||
// Signal that the module has been initialized.
|
||||
// This indicates that the module is ready for use, with the default filter
|
||||
defer close(moduleInitDone)
|
||||
|
||||
ver, err := getCacheDatabaseVersion()
|
||||
if err == nil {
|
||||
log.Debugf("intel/filterlists: cache database has version %s", ver.String())
|
||||
@@ -108,6 +115,7 @@ func start() error {
|
||||
}
|
||||
|
||||
func stop() error {
|
||||
moduleInitDone = make(chan struct{})
|
||||
filterListsLoaded = make(chan struct{})
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user