allegro / allegro/bigcache

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

Đang mở
#283 8 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Go
Star
8.2k
Fork
614
Merge trung bình
5 ngày 12 giờ
Pull request đã merge (30 ngày)
1

Mô tả

**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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.