bluele / gcache

An in-memory cache library for golang. It supports multiple eviction policies: LRU, LFU, ARC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ARC Get panicks

nielsole opened this issue · comments

Hi,

thanks for the caching library. While trying to integrate this into a project I work on I receive the following panick reproducibly(after a variable time of 20sec~1min):

[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x625f06]

goroutine 36 [running]:
panic(0x7ba5a0, 0xc42000c0c0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/bluele/gcache.(*arcItem).IsExpired(0x0, 0x0, 0xc43612dd30)
	/src/github.com/bluele/gcache/arc.go:311 +0x26
github.com/bluele/gcache.(*ARC).get(0xc4200ab9a0, 0x7979c0, 0xc429f6a680, 0xc4438e5c00, 0x88, 0x822d00, 0xc43612de08, 0x411d05)
	/src/github.com/bluele/gcache/arc.go:178 +0x22f
github.com/bluele/gcache.(*ARC).getValue(0xc4200ab9a0, 0x7979c0, 0xc429f6a680, 0xc43612de30, 0x40dfbb, 0x7979c0, 0xc429f6a680)
	/src/github.com/bluele/gcache/arc.go:205 +0x48
github.com/bluele/gcache.(*ARC).GetIFPresent(0xc4200ab9a0, 0x7979c0, 0xc429f6a680, 0x7979c0, 0xc429f6a680, 0x0, 0xc421373540)
	/src/github.com/bluele/gcache/arc.go:142 +0x43
...

I tried replacing all locks within the function with a RW lock that wraps the function but this also yields the same panick. So I guess the error is somewhere else.

My code has about 10 workers that share the cache. I could probably make the cache only available to one worker at a time but I guess that wouldn't solve the root of the problem.

I only call the cache in two different places:

cache := gcache.New(1000).ARC().Build()
cache.Set(domain,robotsTxt) and cache.GetIFPresent(domain)

Do you have any idea what causes this?

Best
Niels-Ole

I switched libraries so this problem does not affect me anymore. Leaving it here for others using this library.