bigcache icon indicating copy to clipboard operation
bigcache copied to clipboard

The problem still exists in version 3.0.1,panic: runtime error: index out of range [7] with length 0

Open 784909593 opened this issue 3 years ago • 8 comments

In theory, this issues is fix in v3.0.1, but I still met

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

runtime/debug.Stack()
        /home/xx/Apps/go/src/runtime/debug/stack.go:24 +0x65
golang.org/x/sync/singleflight.newPanicError({0x120c9a0, 0xc26e4c02d0})
        /home/xx/.go/pkg/mod/golang.org/x/[email protected]/singleflight/singleflight.go:35 +0x2c
golang.org/x/sync/singleflight.(*Group).doCall.func2.1()
        /home/xx/.go/pkg/mod/golang.org/x/[email protected]/singleflight/singleflight.go:188 +0x3b
panic({0x120c9a0, 0xc26e4c02d0})
        /home/xx/Apps/go/src/runtime/panic.go:1038 +0x215
encoding/binary.littleEndian.Uint64(...)
        /home/xx/Apps/go/src/encoding/binary/binary.go:77
github.com/allegro/bigcache/v3.readTimestampFromEntry(...)
        /home/xx/.go/pkg/mod/github.com/allegro/bigcache/[email protected]/encoding.go:58
github.com/allegro/bigcache/v3.(*cacheShard).onEvict(0xc0edece368, {0xc377a92025, 0x50beccc039db3211, 0x0}, 0x0, 0x0)
        /home/xx/.go/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:271 +0x65
github.com/allegro/bigcache/v3.(*cacheShard).set(0xc0edece360, {0xc2326b0550, 0x4d}, 0x0, {0xc0dc931800, 0x7e, 0x400})
        /home/xx/.go/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:134 +0x1a5
github.com/xx/bigcache/v3.(*BigCache).Set(0xc0001b61a0, {0xc2326b0550, 0x4d}, {0xc0dc931800, 0x7e, 0x400})
        /home/xx/.go/pkg/mod/github.com/allegro/bigcache/[email protected]/bigcache.go:133 +0x8d
git.yfcloud.com/supercdn/supercdn_group/scheduler/minerpool/src/cache.(*customCache).Set(...)
        /home/xx/Codes/go/scdn/scheduler/minerpool/src/cache/custom_cache.go:59

@janisz I had the same problem with the same version, but it's hard to find a stable reproducible case. This problem will cause bigcache deadlock, and the hidden danger is very large.

Originally posted by @784909593 in https://github.com/allegro/bigcache/issues/283#issuecomment-1010832915

784909593 avatar Jan 12 '22 09:01 784909593

Thanks for reporting this. Indeed without minimal reproducible example it's super hard to prepare a fix and ensure it was really fixed.

janisz avatar Jan 18 '22 10:01 janisz

panic(0x175a640, 0xc01e3d3b20)
/var/jenkins_home/go/go1.15.6/src/runtime/panic.go:975 +0x47a
encoding/binary.littleEndian.Uint64(...)
/var/jenkins_home/go/go1.15.6/src/encoding/binary/binary.go:77
github.com/allegro/bigcache/v3.readTimestampFromEntry(...)
/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/encoding.go:58
github.com/allegro/bigcache/v3.(*cacheShard).onEvict(0xc00037b8c0, 0xc023bc0f6a, 0x0, 0x57dbe, 0x6204692b, 0xc01e6b06a8, 0x0)
/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:271 +0x85
github.com/allegro/bigcache/v3.(*cacheShard).set(0xc00037b8c0, 0xc01e3ed930, 0xd, 0xc7022ec1611f8c45, 0xc01de4f400, 0x3ce, 0x400, 0x3ce, 0xc01de4f400)
/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:134 +0x31a
github.com/allegro/bigcache/v3.(*BigCache).Set(0xc0000a6dd0, 0xc01e3ed930, 0xd, 0xc01de4f400, 0x3ce, 0x400, 0x0, 0x0)
/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/bigcache.go:133 +0xac

go version 1.15, same panic stack

JamesSunXX avatar Feb 10 '22 01:02 JamesSunXX

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

goroutine 57 [running]:
encoding/binary.littleEndian.Uint64(...)
	/var/jenkins_home/go/go1.15.6/src/encoding/binary/binary.go:77
github.com/allegro/bigcache/v3.readTimestampFromEntry(...)
	/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/encoding.go:58
github.com/allegro/bigcache/v3.(*cacheShard).onEvict(0xc00777eb40, 0xc025622171, 0x0, 0x6cbb7, 0x62036d13, 0xc000056e40, 0x0)
	/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:271 +0x85
github.com/allegro/bigcache/v3.(*cacheShard).cleanUp(0xc00777eb40, 0x62036d13)
	/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/shard.go:284 +0xb6
github.com/allegro/bigcache/v3.(*BigCache).cleanUp(0xc0004e00d0, 0x62036d13)
	/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/bigcache.go:215 +0x53
github.com/allegro/bigcache/v3.newBigCache.func1(0x400, 0x1a3185c5000, 0x8bb2c97000, 0x927c0, 0x1f4, 0x0, 0x1b17260, 0x2823c78, 0x1000, 0x0, ...)
	/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/bigcache.go:92 +0x9b
created by github.com/allegro/bigcache/v3.newBigCache
	/root/go/pkg/mod/github.com/allegro/bigcache/[email protected]/bigcache.go:86 +0x4a5

another panic stack

JamesSunXX avatar Feb 10 '22 05:02 JamesSunXX

1.17.6 same prob.

2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 2340000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 532.4µs; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 46.7µs; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 598.7µs; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 17.2µs; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 550.1µs; Capacity: 1170000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:09 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:10 Allocated new queue in 0s; Capacity: 585000 2022/02/11 16:13:10 Allocated new queue in 0s; Capacity: 585000 panic: runtime error: index out of range [7] with length 0

goroutine 224 [running]: encoding/binary.littleEndian.Uint64(...) c:/go/src/encoding/binary/binary.go:77

temuera avatar Feb 11 '22 08:02 temuera

I am not sure, but it looks like https://github.com/allegro/bigcache/pull/266 is missing in 3.0.1 This could be a reason for the panic

Fabianexe avatar Feb 14 '22 08:02 Fabianexe

@JamesSunXX @784909593 Could you try https://github.com/allegro/bigcache/releases/tag/v3.0.2

janisz avatar Feb 14 '22 10:02 janisz

@JamesSunXX @784909593 Could you try https://github.com/allegro/bigcache/releases/tag/v3.0.2

After reading this issue https://github.com/allegro/bigcache/issues/300, I temporarily used the master 77bbe version, and this problem did not happen again

784909593 avatar Feb 14 '22 13:02 784909593

This issue is the same as https://github.com/allegro/bigcache/issues/290 is it resolved?

blackbeans avatar Aug 19 '22 03:08 blackbeans