Skip to content

Panic when using expirable cache #181

@kalafut

Description

@kalafut

When testing with an expirable.LRU, I've seen the crash below. I was using size=100 and expiration=1 second, and the access pattern was all around a single key. The test had a couple concurrent reads per second, and a write of the same key any time there was a cache miss. I'd reliably hit this panic after a few seconds.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x102c011b8]

goroutine 21 [running]:
github.com/hashicorp/golang-lru/v2/internal.(*LruList[...]).Remove(...)
	/Users/kalafut/go/pkg/mod/github.com/hashicorp/golang-lru/v2@v2.0.7/internal/list.go:97
github.com/hashicorp/golang-lru/v2/expirable.(*LRU[...]).removeElement(0x140001c6ff0?, 0x1400020aea8?)
	/Users/kalafut/go/pkg/mod/github.com/hashicorp/golang-lru/v2@v2.0.7/expirable/expirable_lru.go:298 +0x28
github.com/hashicorp/golang-lru/v2/expirable.(*LRU[...]).deleteExpired(0x102fb2c20)
	/Users/kalafut/go/pkg/mod/github.com/hashicorp/golang-lru/v2@v2.0.7/expirable/expirable_lru.go:319 +0x20c
github.com/hashicorp/golang-lru/v2/expirable.NewLRU[...].func1()
	/Users/kalafut/go/pkg/mod/github.com/hashicorp/golang-lru/v2@v2.0.7/expirable/expirable_lru.go:90 +0xa0
created by github.com/hashicorp/golang-lru/v2/expirable.NewLRU[...] in goroutine 1
	/Users/kalafut/go/pkg/mod/github.com/hashicorp/golang-lru/v2@v2.0.7/expirable/expirable_lru.go:82 +0x2b8
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions