diff --git a/service/intel/filterlists/database.go b/service/intel/filterlists/database.go index 7653a5f4..296ac347 100644 --- a/service/intel/filterlists/database.go +++ b/service/intel/filterlists/database.go @@ -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() diff --git a/service/intel/filterlists/module.go b/service/intel/filterlists/module.go index fd780890..f2780e5f 100644 --- a/service/intel/filterlists/module.go +++ b/service/intel/filterlists/module.go @@ -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 }