Improve locking in intel/geoip
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user