fatal error: concurrent map read and map write
Closed this issue · 4 comments
I sometimes run into this error, are you going to implement RWMutex by any chance?
fatal error: concurrent map read and map write
goroutine 6686 [running]:
runtime.throw(0xb5f048, 0x21)
/usr/lib/go-1.8/src/runtime/panic.go:596 +0x95 fp=0xc423619408 sp=0xc4236193e8
runtime.mapaccess2_faststr(0xa854e0, 0xc423d02510, 0xb4eab4, 0x9, 0xc424c805f0, 0xc423619578)
/usr/lib/go-1.8/src/runtime/hashmap_fast.go:326 +0x50a fp=0xc423619468 sp=0xc423619408
github.com/Jeffail/gabs.(*Container).Search(0xc42446de40, 0xc4236196f0, 0x1, 0x1, 0xf)
/home/mda/.local/go/src/github.com/Jeffail/gabs/gabs.go:98 +0xb1 fp=0xc423619550 sp=0xc423619468
github.com/Jeffail/gabs.(*Container).Exists(0xc42446de40, 0xc4236196f0, 0x1, 0x1, 0xc424c805f0)
/home/mda/.local/go/src/github.com/Jeffail/gabs/gabs.go:129 +0x49 fp=0xc423619588 sp=0xc423619550
...
Hey @mdaliyan, I think a mutex lock would be better off implemented outside of gabs, since the library in the majority of cases probably isn't shared across goroutines and there's a performance cost for adding it.
If you want to avoid wrapping the gabs container as a field you should be able to do it with inheritance like this:
type RWGabs struct {
sync.RWMutex
*gabs.Container
}
I'm afraid, I'm not passing the container between goroutines but i get this error some times only on Exists function.
Hey @mdaliyan, for that crash to occur there must be some sharing between goroutines. Try running go test -race
and it might reveal where it happens.
In my case, every usage of the gabs package was in goroutines, so adding mutex lock to my code made it messy.
I had to fork gabs and add mutex lock
to it. Hope it helps some one else too. mdaliyan/gabs