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

Fixed alignment of int64, to be able to access it with atomic.LoadInt64 #294

Merged
merged 1 commit into from
Dec 13, 2019

Conversation

dm4tze
Copy link

@dm4tze dm4tze commented Dec 9, 2019

On ARM (Raspberry Pi 3) following error occurs when starting emitter:

2019/12/09 11:54:58 [async] panic recovered: runtime error: invalid memory address or nil pointer dereferences
 goroutine 1 [running]:
runtime/debug.Stack(0x28fbaa4, 0xabcee0, 0x116b7a8)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x78
github.com/emitter-io/emitter/internal/async.handlePanic()
        /go/src/github.com/emitter-io/emitter/internal/async/timer.go:58 +0x3c
panic(0xabcee0, 0x116b7a8)
        /usr/local/go/src/runtime/panic.go:679 +0x194
runtime/internal/atomic.goLoad64(0x2a3075c, 0xb6863e, 0xa)
        /usr/local/go/src/runtime/internal/atomic/atomic_arm.go:131 +0x1c
github.com/emitter-io/emitter/internal/broker.(*sampler).Snapshot(0x280ee00, 0x8, 0x2810b40, 0x0)
        /go/src/github.com/emitter-io/emitter/internal/broker/status.go:51 +0xec
github.com/emitter-io/emitter/internal/provider/monitor.(*Self).write(0x280d480)
        /go/src/github.com/emitter-io/emitter/internal/provider/monitor/self.go:80 +0x28
...

This is caused by a bug in the atomic package, which only allows to access 64-bit data fields if they are aligned. See https://golang.org/pkg/sync/atomic/#pkg-note-BUG

On ARM, x86-32, and 32-bit MIPS, it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically.

The bug descriptions also says,

The first word in a variable or in an allocated struct, array, or slice can be relied upon to be 64-bit aligned.

so I moved the field to the beginning of the struct.

@kelindar kelindar merged commit 2b188eb into emitter-io:master Dec 13, 2019
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

Successfully merging this pull request may close these issues.

2 participants