sentinel-golang icon indicating copy to clipboard operation
sentinel-golang copied to clipboard

[BUG] Integer overflow on 32-bit startup

Open kb2ma opened this issue 4 years ago • 2 comments

Issue Description

Type: bug report

Crash at startup due to integer overlow on 32-bit platform

Describe what happened

Sentinel is a plugin feature in dapr's latest release v1.2.2. Startup is triggered with api.initWithConfig() within a Docker container. Usually I see an error like below, except the out of range value changes but is always negative.

panic: runtime error: index out of range [-17]

goroutine 1 [running]:
github.com/alibaba/sentinel-golang/core/stat/base.NewAtomicBucketWrapArrayWithTime(0x14, 0x1f4, 0x6a05bff2, 0x17a, 0x2f04df4, 0x4b686a0, 0x4b686a0)
	/home/runner/go/pkg/mod/github.com/alibaba/[email protected]/core/stat/base/leap_array.go:83 +0x334
github.com/alibaba/sentinel-golang/core/stat/base.NewAtomicBucketWrapArray(0x14, 0x1f4, 0x2f04df4, 0x4b686a0, 0xf9c)
	/home/runner/go/pkg/mod/github.com/alibaba/[email protected]/core/stat/base/leap_array.go:108 +0x48
github.com/alibaba/sentinel-golang/core/stat/base.NewBucketLeapArray(0x14, 0x2710, 0x11f18)
	/home/runner/go/pkg/mod/github.com/alibaba/[email protected]/core/stat/base/bucket_leap_array.go:60 +0x84
github.com/alibaba/sentinel-golang/core/stat.NewBaseStatNode(0x2, 0x3e8, 0x66c63009)
	/home/runner/go/pkg/mod/github.com/alibaba/[email protected]/core/stat/base_node.go:36 +0x30
github.com/alibaba/sentinel-golang/core/stat.NewResourceNode(0x29d5d0f, 0x19, 0x0, 0x1c920)
	/home/runner/go/pkg/mod/github.com/alibaba/[email protected]/core/stat/resource_node.go:32 +0x34
github.com/alibaba/sentinel-golang/core/stat.init()
	/home/runner/go/pkg/mod/github.com/alibaba/[email protected]/core/stat/node_storage.go:27 +0x2c

Describe what you expected to happen

No crash!

How to reproduce it (as minimally and precisely as possible)

Nothing special to trigger the problem. I expect the error to happen on any 32-bit platform.

Tell us your environment

Running sentinel v1.0.2 on a Raspberry Pi Compute Module 3+, compiled for linux/arm architecture.

Anything else we need to know?

Debugging shows the issue pretty clearly is here. timeId is Unix epoch time in msec, a 64-bit value; len is 500.

kb2ma avatar Jul 19 '21 22:07 kb2ma

Thanks for reporting. We'll fix it soon.

sczyh30 avatar Jul 20 '21 02:07 sczyh30

FWIW, I have implemented a workaround.

kb2ma avatar Jul 21 '21 14:07 kb2ma

Fixed in #429

sczyh30 avatar Oct 11 '22 11:10 sczyh30