Browse Source

geoip2: add read lock to GetLocation

bug: read lock missing from GetLocation

GetLocation operates on a *geoip2.City (pointer) but does not incur a
read-lock on the GeoIP struct like other functions.
Tyler Davis 4 years ago
parent
commit
d5ab161fab
1 changed files with 4 additions and 0 deletions
  1. 4 0
      targeting/geoip2/geoip2.go

+ 4 - 0
targeting/geoip2/geoip2.go

@@ -268,6 +268,10 @@ func (g *GeoIP2) HasLocation() (bool, error) {
 
 // GetLocation returns a geo.Location object for the given IP
 func (g *GeoIP2) GetLocation(ip net.IP) (l *geo.Location, err error) {
+	// Need a read-lock because return value of City is a pointer, not copy of the struct/object
+	g.mu.RLock()
+	defer g.mu.RUnlock()
+
 	c, err := g.city.db.City(ip)
 	if err != nil {
 		log.Printf("Could not lookup CountryRegion for '%s': %s", ip.String(), err)