diff --git a/component/mmdb/mmdb.go b/component/mmdb/mmdb.go index d411b2b4..24edb5e5 100644 --- a/component/mmdb/mmdb.go +++ b/component/mmdb/mmdb.go @@ -57,7 +57,7 @@ func Verify() bool { func Instance() Reader { once.Do(func() { mmdbPath := C.Path.MMDB() - log.Debugln("Load MMDB file: %s", mmdbPath) + log.Infoln("Load MMDB file: %s", mmdbPath) mmdb, err := maxminddb.Open(mmdbPath) if err != nil { log.Fatalln("Can't load MMDB: %s", err.Error()) @@ -94,3 +94,7 @@ func DownloadMMDB(path string) (err error) { return err } + +func Reload() { + once = sync.Once{} +} diff --git a/config/update_geo.go b/config/update_geo.go index 2cde47a1..bf3d0810 100644 --- a/config/update_geo.go +++ b/config/update_geo.go @@ -6,6 +6,7 @@ import ( "github.com/metacubex/mihomo/component/geodata" _ "github.com/metacubex/mihomo/component/geodata/standard" + "github.com/metacubex/mihomo/component/mmdb" C "github.com/metacubex/mihomo/constant" "github.com/oschwald/maxminddb-golang" @@ -33,6 +34,7 @@ func UpdateGeoDatabases() error { } } else { + defer mmdb.Reload() data, err := downloadForBytes(C.MmdbUrl) if err != nil { return fmt.Errorf("can't download MMDB database file: %w", err) @@ -43,6 +45,8 @@ func UpdateGeoDatabases() error { return fmt.Errorf("invalid MMDB database file: %s", err) } _ = instance.Close() + + mmdb.Instance().Reader.Close() // mmdb is loaded with mmap, so it needs to be closed before overwriting the file if err = saveFile(data, C.Path.MMDB()); err != nil { return fmt.Errorf("can't save MMDB database file: %w", err) }