Improve locking in intel/geoip

This commit is contained in:
Patrick Pacher
2021-08-17 13:47:17 +02:00
parent 09bba4198a
commit 3627384fc5
2 changed files with 4 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ var (
geoDBv4Reader *maxminddb.Reader
geoDBv6Reader *maxminddb.Reader
dbLock sync.Mutex
dbLock sync.RWMutex
dbInUse = abool.NewBool(false) // only activate if used for first time
dbDoReload = abool.NewBool(true) // if database should be reloaded
@@ -35,6 +35,7 @@ func ReloadDatabases() error {
dbFileLock.Lock()
defer dbFileLock.Unlock()
dbLock.Lock()
defer dbLock.Unlock()

View File

@@ -15,8 +15,8 @@ func getReader(ip net.IP) *maxminddb.Reader {
// GetLocation returns Location data of an IP address
func GetLocation(ip net.IP) (record *Location, err error) {
dbLock.Lock()
defer dbLock.Unlock()
dbLock.RLock()
defer dbLock.RUnlock()
err = prepDatabaseForUse()
if err != nil {