bigcache
bigcache copied to clipboard
panic: runtime error: slice bounds out of range [16:0]
What is the issue you are having? Panic when calling Get()
2020-11-26 14:27:29.336176 I | Allocated new queue in 841.579µs; Capacity: 2340000
panic: runtime error: slice bounds out of range [16:0]
goroutine 33821663 [running]:
github.com/allegro/bigcache/v2.readKeyFromEntry(...)
/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/encoding.go:47
github.com/allegro/bigcache/v2.(*cacheShard).get(0xc0259f10e0, 0xc057fafac0, 0x20, 0x2f40a1f0106a7737, 0x0, 0x0, 0xc057fe9490, 0xc057fcdc40, 0xc05830adb0)
/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:69 +0x657
github.com/allegro/bigcache/v2.(*BigCache).Get(0xc00230aa90, 0xc057fafac0, 0x20, 0x2741b20, 0xc058332f70, 0x0, 0x0, 0x0)
/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/bigcache.go:117 +0x8b
What is BigCache doing that it shouldn't? Panic
Minimal, Complete, and Verifiable Example
My service do a high number of get operations.
This is my config:
expiry := 7 * time.Minute
conf := bigcache.DefaultConfig(expiry)
conf.CleanWindow = expiry * 3
conf.HardMaxCacheSize = 8192
conf.OnRemoveWithReason = func(_ string, entry []byte, reason bigcache.RemoveReason) {
// monitoring
}
Environment:
- Version (git sha or release): v2.2.4
- OS (e.g. from
/etc/os-releaseor winver.exe): Ubuntu 16.04.6 LTS - go version: 1.15
the key is too long.
example:
package main
import (
"time"
"github.com/allegro/bigcache/v2"
)
func main() {
c := bigcache.DefaultConfig(3 * time.Second)
ca, err := bigcache.NewBigCache(c)
if err != nil {
panic(err)
}
k := make([]byte, 65530)// 1<<16-18+12
v := make([]byte, 1)
ca.Set(string(k), v)
ca.Get(string(k))
}