muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Fatal ERROR when concurrent map write and read

daymade opened this issue · comments

go version

go version go1.9 darwin/amd64

log

fatal error: concurrent map iteration and map write

goroutine 177777 [running]:
runtime.throw(0xbeb3a9, 0x26)
	/go1.9/src/runtime/panic.go:605 +0x95 fp=0xc422b05610 sp=0xc422b055f0 pc=0x42e9f5
runtime.mapiternext(0xc422b05768)
	/go1.9/src/runtime/hashmap.go:778 +0x6f1 fp=0xc422b056a8 sp=0xc422b05610 pc=0x40d0a1
github.com/muesli/cache2go.(*CacheTable).expirationCheck(0xc42007e060)
	/src/github.com/muesli/cache2go/cachetable.go:111 +0x247 fp=0xc422b057d8 sp=0xc422b056a8 pc=0x578d97
runtime.goexit()
	/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc422b057e0 sp=0xc422b057d8 pc=0x45f7b1
created by github.com/muesli/cache2go.(*CacheTable).expirationCheck.func1
	/src/github.com/muesli/cache2go/cachetable.go:137 +0x3e
commented

I was able to fix this problem by using this commit version a299e7f. As it has a change that uses a mutex to stop common reads.

But it doesn't seem like it is available in the latest release tag.

@adam-cv You're absolutely right, I should push a new release asap.

Should you still be able to reproduce this with v0.2, please let me know here.