allegro / allegro/bigcache

panic: runtime error: index out of range [7] with length 0

Abierto
#283 8 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Go
Estrellas
8.2k
Forks
614
Merge medio
5 d 12 h
PR fusionados (30 d)
1

Descripción

**What is the issue you are having?**

Run for a few seconds and panic

`panic: runtime error: index out of range [7] with length 0`

```
goroutine 60 [running]:
encoding/binary.littleEndian.Uint64(...)
/usr/local/go/src/encoding/binary/binary.go:77
github.com/allegro/bigcache/v2.readTimestampFromEntry(...)
/Users/xx/go/pkg/mod/github.com/allegro/bigcache/v2@v2.2.5/encoding.go:58
github.com/allegro/bigcache/v2.(*cacheShard).onEvict(0xc00010cd80, 0xc0029a02fb, 0x0, 0x9845, 0x60f94108, 0xc000278f00, 0x0)
/Users/xx/go/pkg/mod/github.com/allegro/bigcache/v2@v2.2.5/shard.go:269 +0x85
github.com/allegro/bigcache/v2.(*cacheShard).set(0xc00010cd80, 0xc004e976f8, 0x13, 0x16c4e5b3aad5055c, 0xc004d785d8, 0x6, 0x6, 0x6, 0xc004d785d8)
/Users/xx/go/pkg/mod/github.com/allegro/bigcache/v2@v2.2.5/shard.go:132 +0x31a
github.com/allegro/bigcache/v2.(*BigCache).Set(0xc00009aea0, 0xc004e976f8, 0x13, 0xc004d785d8, 0x6, 0x6, 0x0, 0x0)
/Users/xx/go/pkg/mod/github.com/allegro/bigcache/v2@v2.2.5/bigcache.go:133 +0xac
main.main.func1(0xc00009aea0)
/Users/xx/go/src/x/vod/scheduler/manager/local_cache/example2/main.go:26 +0x7c
created by main.main
/Users/xx/go/src/x/vod/scheduler/manager/local_cache/example2/main.go:24 +0xf8
exit status 2

```

**Minimal, Complete, and Verifiable Example**

```
package main

import (
"fmt"
"math/rand"
"time"

"github.com/allegro/bigcache/v2"
)

func main() {
bc, _ := bigcache.NewBigCache(bigcache.DefaultConfig(time.Second))

for i := 0; i < 100; i++ {
go func() {
for {
_ = bc.Set(randPath(), randValue())
}
}()
}

select {}
}

func randPath() string {
return fmt.Sprintf("%d", rand.Int())
}

func randValue() []byte {
length := rand.Intn(1000)
data := make([]byte, length)
for i := 0; i < length; i++ {
data[i] = byte(rand.Uint32())
}
return data
}
```

**Environment:**
- Version (git sha or release): v2.2.5
- OS: darwin/amd64
- go version: go1.16.6

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.