pariz / gountries

Gountries provides: Countries (ISO-3166-1), Country Subdivisions(ISO-3166-2), Currencies (ISO 4217), Geo Coordinates(ISO-6709) as well as translations, country borders and other stuff exposed as struct data.
MIT License
408 stars 67 forks source link

Calling New() concurrently creates data race because of concurrent access to queryInstance global variable #28

Closed drscre closed 2 years ago

drscre commented 4 years ago

I think, we should get rid of global instances at all

q1 := gountries.NewFromPath('path1') 
q2 := gountries.NewFromPath('path2') // SURPRISE! q2 actually is q1
sevvy325 commented 4 years ago

I have also seen this issue.

fatal error: concurrent map writes

goroutine 64 [running
]:
runtime.throw(0x93d29a,
0x15)
    /usr/local/go/src/runtime/panic.go: 774 +0x72 fp=0xc000750cc0 sp=0xc000750c90 pc=0x42ede2
runtime.mapassign(0x8b0820,
0xc0006e6f60,
0xc000750dc0,
0xc0008b2140)
    /usr/local/go/src/runtime/map.go: 680 +0x5aa fp=0xc000750d48 sp=0xc000750cc0 pc=0x40f6da
***/github.com/pariz/gountries.NewFromPath(0xc0003ad790,
0x9,
bastengao commented 4 years ago

+1