allegro / bigcache

Efficient cache for gigabytes of data written in Go.
http://allegro.tech/2016/03/writing-fast-cache-service-in-go.html
Apache License 2.0
7.45k stars 593 forks source link

compile a 32-bit LSB executable on arm and Execution error-> panic: unaligned 64-bit atomic operation #368

Open 912929782 opened 1 year ago

912929782 commented 1 year ago

What is the issue you are having? panic: unaligned 64-bit atomic operation

goroutine 1 [running]:
runtime/internal/atomic.panicUnaligned()
        C:/GoSDK/src/runtime/internal/atomic/unaligned.go:8 +0x24
runtime/internal/atomic.Xadd64(0x13571684, 0x1)
        C:/GoSDK/src/runtime/internal/atomic/atomic_arm.s:258 +0x14
github.com/allegro/bigcache/v3.(*cacheShard).hit(0x13571600, 0x5819c5d75cbda787)
        C:/Users/Joker/go/pkg/mod/github.com/allegro/bigcache/v3@v3.1.0/shard.go:403 +0x34
github.com/allegro/bigcache/v3.(*cacheShard).get(0x13571600, {0x214747, 0x4}, 0x5819c5d75cbda787)
        C:/Users/Joker/go/pkg/mod/github.com/allegro/bigcache/v3@v3.1.0/shard.go:79 +0x3d0
github.com/allegro/bigcache/v3.(*BigCache).Get(0x2498980, {0x214747, 0x4})
        C:/Users/Joker/go/pkg/mod/github.com/allegro/bigcache/v3@v3.1.0/bigcache.go:136 +0x8c
janisz commented 1 year ago

On ARM, 386, and 32-bit MIPS, it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically via the primitive atomic functions (types Int64 and Uint64 are automatically aligned). The first word in an allocated struct, array, or slice; in a global variable; or in a local variable (because the subject of all atomic operations will escape to the heap) can be relied upon to be 64-bit aligned.

https://pkg.go.dev/sync/atomic#pkg-notes

So maybe we should switch to atomic.Int64 from int64

janisz commented 1 year ago

I see 3 options:

@912929782 How to reproduce this issue? Does it happen with go test ./... we'll need to extend our CI with non x86 arch https://github.com/marketplace/actions/run-on-architecture

912929782 commented 1 year ago

I expect this problem to occur on x86 systems as well

912929782 commented 1 year ago

Forget to say, I am in the library: https://github.com/jpillora/overseer to use bigcache operation, result in this error. @janisz

mgwoj commented 3 weeks ago

What help is needed to fix this issue?

janisz commented 3 weeks ago

We need to reproduce it, best in CI. Maybe we can use qemu for that :thinking: