File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,12 @@ import (
24
24
25
25
type GeoIP struct {
26
26
db * C.GeoIP
27
+
28
+ // We don't use GeoIP's thread-safe API calls, which means there is a
29
+ // single global netmask variable that gets clobbered in the main
30
+ // lookup routine. Any calls which have _GeoIP_seek_record_gl need to
31
+ // be wrapped in this mutex.
32
+
27
33
mu sync.Mutex
28
34
}
29
35
@@ -178,7 +184,11 @@ func (gi *GeoIP) GetRecord(ip string) *GeoIPRecord {
178
184
179
185
cip := C .CString (ip )
180
186
defer C .free (unsafe .Pointer (cip ))
187
+
188
+ gi .mu .Lock ()
181
189
record := C .GeoIP_record_by_addr (gi .db , cip )
190
+ gi .mu .Unlock ()
191
+
182
192
if record == nil {
183
193
return nil
184
194
}
@@ -209,7 +219,11 @@ func (gi *GeoIP) GetRegion(ip string) (string, string) {
209
219
210
220
cip := C .CString (ip )
211
221
defer C .free (unsafe .Pointer (cip ))
222
+
223
+ gi .mu .Lock ()
212
224
region := C .GeoIP_region_by_addr (gi .db , cip )
225
+ gi .mu .Unlock ()
226
+
213
227
if region == nil {
214
228
return "" , ""
215
229
}
@@ -270,7 +284,7 @@ func (gi *GeoIP) GetCountry(ip string) (cc string, netmask int) {
270
284
return
271
285
}
272
286
273
- gi .mu .Lock () // Lock to make sure we get the right result from GeoIP_last_netmask
287
+ gi .mu .Lock ()
274
288
defer gi .mu .Unlock ()
275
289
276
290
cip := C .CString (ip )
You can’t perform that action at this time.
0 commit comments