Skip to content

Commit

Permalink
geoip2: add read lock to GetLocation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tydavis committed Oct 19, 2021
1 parent 0b19890 commit d5ab161
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions targeting/geoip2/geoip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d5ab161

Please sign in to comment.