aws-sdk-go icon indicating copy to clipboard operation
aws-sdk-go copied to clipboard

Fix misaligned struct member used in atomic operation

Open dswarbrick opened this issue 1 year ago • 3 comments

This fixes a panic caused by attempting to atomically access a struct member which is not 64-bit aligned when running on 32-bit arch, due to the smaller sync.Map struct. For example:

$ GOARCH=386 go test -run TestCacheAdd
--- FAIL: TestCacheAdd (0.00s)
panic: unaligned 64-bit atomic operation [recovered]
        panic: unaligned 64-bit atomic operation

goroutine 18 [running]:
testing.tRunner.func1.2({0x82a03c0, 0x85de888})
        /usr/lib/go-1.21/src/testing/testing.go:1545 +0x2ab
testing.tRunner.func1()
        /usr/lib/go-1.21/src/testing/testing.go:1548 +0x43e
panic({0x82a03c0, 0x85de888})
        /usr/lib/go-1.21/src/runtime/panic.go:914 +0x1ec
runtime/internal/atomic.panicUnaligned()
        /usr/lib/go-1.21/src/runtime/internal/atomic/unaligned.go:8 +0x2d
runtime/internal/atomic.Xadd64(0xa4c625c, 0x1)
        /usr/lib/go-1.21/src/runtime/internal/atomic/atomic_386.s:125 +0x11
github.com/aws/aws-sdk-go/aws/crr.(*EndpointCache).Add(0xa4c6240, {{0x82c9971, 0x3}, {0xa4c83f0, 0x1, 0x1}})
        /home/daniel/src/aws-sdk-go/aws/crr/cache.go:89 +0x141
github.com/aws/aws-sdk-go/aws/crr.TestCacheAdd(0xa6904b0)
        /home/daniel/src/aws-sdk-go/aws/crr/cache_test.go:204 +0x144c
testing.tRunner(0xa6904b0, 0x82efa7c)
        /usr/lib/go-1.21/src/testing/testing.go:1595 +0x120
created by testing.(*T).Run in goroutine 1
        /usr/lib/go-1.21/src/testing/testing.go:1648 +0x3dd
exit status 2
FAIL    github.com/aws/aws-sdk-go/aws/crr       0.005s

This is essentially the same issue as https://github.com/aws/aws-sdk-go-v2/issues/2518

Please consider adding testing with a 32-bit GOARCH (e.g. "386") to your CI testing pipeline to avoid such oversights in future.

dswarbrick avatar Feb 27 '24 16:02 dswarbrick

@lucix-aws PTAL

dswarbrick avatar Mar 04 '24 21:03 dswarbrick

Fell of my radar. Will try to address next week. Patch is fine though.

lucix-aws avatar Mar 08 '24 22:03 lucix-aws

Hfcgb

Tiwat2540k avatar Mar 20 '24 21:03 Tiwat2540k

Sorry for the delay. Merging.

lucix-aws avatar May 24 '24 17:05 lucix-aws