Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A compatibility bug on ARM V7 #17

Open
zxxf18 opened this issue Dec 29, 2021 · 4 comments
Open

A compatibility bug on ARM V7 #17

zxxf18 opened this issue Dec 29, 2021 · 4 comments

Comments

@zxxf18
Copy link

zxxf18 commented Dec 29, 2021

Describe the bug
Run time.Sleep(ws.backoff.Duration()) \\ ws.backoff != nil in arm v7 get a runtime error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11e34]

goroutine 51 [running]:
runtime/internal/atomic.goXadd64(0x3db8bcc, 0x1, 0x0, 0x3ea8000, 0x3e9a5e8)
	/usr/local/go/src/runtime/internal/atomic/atomic_arm.go:103 +0x1c
github.com/jpillora/backoff.(*Backoff).Duration(0x3db8bcc, 0xf20220, 0x1cbc5c8)
	/go/pkg/mod/github.com/jpillora/backoff@v1.0.0/backoff.go:30 +0x30

Environment:

  • Infrastructure: on raspberry pi (arm32v7)
  • version: github.com/jpillora/backoff v1.0.0
  • go version: 1.13

Analyze:

  • The details of what operating system (specifically that it was 32bit) were key here to figuring this one out!
  • Note, this has to be defined first to make sure it is aligned properly for 32bit ARM OS
  • From https://golang.org/pkg/sync/atomic/#pkg-note-BUG
  • 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. The first word in a variable or in an allocated struct, array, or slice can be relied upon to be 64-bit aligned.
@jpillora
Copy link
Owner

jpillora commented Dec 29, 2021 via email

@zxxf18
Copy link
Author

zxxf18 commented Dec 30, 2021

In go1.17.5, this problem still exists.
https://golang.org/pkg/sync/atomic/#pkg-note-BUG
This is not a must-have problem, it sometimes works normally.

@ykholm
Copy link

ykholm commented May 22, 2023

"@jpillora Our team is using go 1.18, and our QA caught this error after building the service for GOOS=linux GOARCH=arm GOARM=7.

Here is the panic stack trace:

time="2023-05-20T12:26:05-05:00" level=error msg="App error" APP=gateway ERR="panic: unaligned 64-bit atomic operation
goroutine 82 [running]:
runtime/internal/atomic.panicUnaligned()
  /usr/local/go/src/runtime/internal/atomic/unaligned.go:8 +0x24
  runtime/internal/atomic.Store64(0x1691d4c, 0x0)
  /usr/local/go/src/runtime/internal/atomic/atomic_arm.s:291 +0x14
github.com/jpillora/backoff.(*Backoff).Reset(...)
  /src/build/go/pkg/mod/github.com/jpillora/backoff@v1.0.0/backoff.go:84."

I must mention that we have previously encountered this issue in our own code, and we resolved it by using an appropriate atomic operation for 32-bit processors: atomic.StoreUint32(&b.attempt, 0) instead of atomic.StoreUint64(&b.attempt, 0).

This fork has already made this change.

@AlekSi
Copy link

AlekSi commented Jun 15, 2023

https://pkg.go.dev/sync/atomic#pkg-note-BUG says:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants