bigcache icon indicating copy to clipboard operation
bigcache copied to clipboard

minimal reproducible example for "index out of range [7] with length 0"

Open temuera opened this issue 3 years ago • 2 comments

2022/02/11 18:13:58 Allocated new queue in 913.9µs; Capacity: 4680000
2022/02/11 18:13:59 Allocated new queue in 10.4696ms; Capacity: 18720000
2022/02/11 18:13:59 Allocated new queue in 9.8986ms; Capacity: 18720000
panic: runtime error: index out of range [7] with length 0

goroutine 479 [running]:
encoding/binary.littleEndian.Uint64(...)
        c:/go/src/encoding/binary/binary.go:77
github.com/allegro/bigcache/v3.readTimestampFromEntry(...)
        d:/mygo/pkg/mod/github.com/allegro/bigcache/[email protected]/encoding.go:58
github.com/allegro/bigcache/v3.(*cacheShard).onEvict(0xc008f81568, {0xc35b048f7b, 0x4121e60c4129bdd3, 0x5}, 0x2600c000014800, 0x5)
        d:/mygo/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:271 +0x65
github.com/allegro/bigcache/v3.(*cacheShard).set(0xc008f81560, {0xc025ae7d70, 0x26}, 0x12f219, {0xc000014800, 0x3ff, 0x400})
        d:/mygo/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:134 +0x1a5
github.com/allegro/bigcache/v3.(*BigCache).Set(0xc00001ca90, {0xc025ae7d70, 0x26}, {0xc000014800, 0x3ff, 0x400})
        d:/mygo/pkg/mod/github.com/allegro/bigcache/[email protected]/bigcache.go:133 +0x8d
main.main.func1()
        d:/mygo/src/test/testbigcache/main.go:31 +0x11a
created by main.main
        d:/mygo/src/test/testbigcache/main.go:26 +0x1ac
package main

import (
	"crypto/md5"
	"encoding/hex"
	"strconv"
	"strings"
	"sync"
	"time"

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

func Md5HashString(str string) string {
	h := md5.New()
	h.Write([]byte(str))
	return hex.EncodeToString(h.Sum(nil))
}
func main() {
	config := bigcache.DefaultConfig(10 * time.Millisecond)
	big, _ := bigcache.NewBigCache(config)
	body := []byte(strings.Repeat("x", 1023))
	var wg sync.WaitGroup
	for i := 0; i < 1000; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			for i := int64(0); i < 10000000; i++ {
				_md5 := Md5HashString(strconv.FormatInt(i, 10))
				_key := _md5 + "_" + strconv.FormatInt(i, 10)
				big.Set(_key, body)
				big.Get(_key)
			}
		}()
	}
	wg.Wait()
}

Win 10 ,Go 1.17.6, BigCache v3.01 100% reproducible.

temuera avatar Feb 11 '22 10:02 temuera

@temuera could you try v3.0.2

janisz avatar Feb 14 '22 11:02 janisz

It looks like it's fixed in v3.0.2

janisz avatar Feb 14 '22 12:02 janisz