fix: timeout waiting for maxmind db on shutdown

This commit is contained in:
yusing 2025-05-04 16:04:17 +08:00
parent 8ef8015a7f
commit 797d88772f
2 changed files with 5 additions and 7 deletions

View file

@ -12,9 +12,6 @@ func SetInstance(parent task.Parent, cfg *Config) gperr.Error {
if err := newInstance.LoadMaxMindDB(parent); err != nil {
return err
}
if instance != nil {
instance.task.Finish("updated")
}
instance = newInstance
return nil
}

View file

@ -22,7 +22,6 @@ import (
type MaxMind struct {
*Config
lastUpdate time.Time
task *task.Task
db struct {
*maxminddb.Reader
sync.RWMutex
@ -70,7 +69,9 @@ func (cfg *MaxMind) LoadMaxMindDB(parent task.Parent) gperr.Error {
return nil
}
cfg.task = parent.Subtask("maxmind_db", true)
init := parent.Subtask("maxmind_db", true)
defer init.Finish(nil)
path := dbPath(cfg)
reader, err := maxmindDBOpen(path)
valid := true
@ -95,7 +96,7 @@ func (cfg *MaxMind) LoadMaxMindDB(parent task.Parent) gperr.Error {
} else {
cfg.Logger().Info().Msg("MaxMind DB loaded")
cfg.db.Reader = reader
go cfg.scheduleUpdate(cfg.task)
go cfg.scheduleUpdate(parent)
}
return nil
}
@ -114,7 +115,7 @@ func (cfg *MaxMind) setLastUpdate(t time.Time) {
}
func (cfg *MaxMind) scheduleUpdate(parent task.Parent) {
task := parent.Subtask("schedule_update", true)
task := parent.Subtask("maxmind_schedule_update", true)
ticker := time.NewTicker(updateInterval)
cfg.loadLastUpdate()