Merge pull request #1990 from safing/fix/1988-redundant-filterlists-update
fix: Unnecessary filterlists database update on service start
This commit is contained in:
@@ -118,14 +118,6 @@ func processListFile(ctx context.Context, filter *scopedBloom, file *updates.Art
|
|||||||
return
|
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.
|
// Process each entry and send records to records channel.
|
||||||
startSafe(func() error {
|
startSafe(func() error {
|
||||||
defer close(records)
|
defer close(records)
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ func (fl *FilterLists) States() *mgr.StateMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fl *FilterLists) Start() error {
|
func (fl *FilterLists) Start() error {
|
||||||
if err := prep(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return start()
|
return start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,26 +43,21 @@ func (fl *FilterLists) Stop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
moduleInitDone chan struct{}
|
|
||||||
|
|
||||||
// booleans mainly used to decouple the module during testing.
|
// booleans mainly used to decouple the module during testing.
|
||||||
ignoreUpdateEvents = abool.New()
|
ignoreUpdateEvents = abool.New()
|
||||||
ignoreNetEnvEvents = abool.New()
|
ignoreNetEnvEvents = abool.New()
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
moduleInitDone = make(chan struct{})
|
|
||||||
|
|
||||||
ignoreNetEnvEvents.Set()
|
ignoreNetEnvEvents.Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
func prep() error {
|
func registerEventCallbacks() {
|
||||||
module.instance.IntelUpdates().EventResourcesUpdated.AddCallback("Check for blocklist updates",
|
module.instance.IntelUpdates().EventResourcesUpdated.AddCallback("Check for blocklist updates",
|
||||||
func(wc *mgr.WorkerCtx, s struct{}) (bool, error) {
|
func(wc *mgr.WorkerCtx, s struct{}) (bool, error) {
|
||||||
if ignoreUpdateEvents.IsSet() {
|
if ignoreUpdateEvents.IsSet() {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
log.Debugf("performing filter list update")
|
|
||||||
|
|
||||||
return false, tryListUpdate(wc.Ctx())
|
return false, tryListUpdate(wc.Ctx())
|
||||||
})
|
})
|
||||||
@@ -82,17 +74,26 @@ func prep() error {
|
|||||||
|
|
||||||
return false, tryListUpdate(wc.Ctx())
|
return false, tryListUpdate(wc.Ctx())
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() error {
|
func start() error {
|
||||||
filterListLock.Lock()
|
filterListLock.Lock()
|
||||||
defer filterListLock.Unlock()
|
defer filterListLock.Unlock()
|
||||||
|
|
||||||
// Signal that the module has been initialized.
|
// Any call of tryListUpdate() must be only after module fully initialized
|
||||||
// This indicates that the module is ready for use, with the default filter
|
defer func() {
|
||||||
defer close(moduleInitDone)
|
// Register event callbacks
|
||||||
|
registerEventCallbacks()
|
||||||
|
|
||||||
|
// Initial check filterlists updates
|
||||||
|
module.Manager().Go("intel/filterlists initial check for update", func(ctx *mgr.WorkerCtx) error {
|
||||||
|
if err := tryListUpdate(ctx.Ctx()); err != nil {
|
||||||
|
log.Errorf("intel/filterlists: tryListUpdate() failed: %q", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
ver, err := getCacheDatabaseVersion()
|
ver, err := getCacheDatabaseVersion()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -115,7 +116,6 @@ func start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stop() error {
|
func stop() error {
|
||||||
moduleInitDone = make(chan struct{})
|
|
||||||
filterListsLoaded = make(chan struct{})
|
filterListsLoaded = make(chan struct{})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user