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

panic: unaligned 64-bit atomic operation. Support 32-bit architectures too. #483

Closed
compliment opened this issue May 8, 2021 · 9 comments

Comments

@compliment
Copy link

compliment commented May 8, 2021

panic: unaligned 64-bit atomic operation

goroutine 489 [running]:
runtime/internal/atomic.panicUnaligned()
        runtime/internal/atomic/unaligned.go:8 +0x24
runtime/internal/atomic.Xadd64(0x2e4e7c4, 0x1, 0x0, 0x2d87600, 0x30a8d40)
        runtime/internal/atomic/asm_arm.s:233 +0x14
github.com/anacrolix/dht/v2.(*traversal).wrapQuery(0x2e4e784, 0xca9b00, 0x2ef6fa0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        github.com/anacrolix/dht/v2@v2.9.1/traversal.go:115 +0x44
github.com/anacrolix/dht/v2.(*traversal).run.func1.1(0x2f8b130)
        github.com/anacrolix/dht/v2@v2.9.1/traversal.go:156 +0x30
github.com/anacrolix/dht/v2.(*traversal).beginQuery.func1.1(0x0)
        github.com/anacrolix/dht/v2@v2.9.1/traversal.go:179 +0x98
github.com/anacrolix/dht/v2.(*Server).beginQuery.func1.1()
        github.com/anacrolix/dht/v2@v2.9.1/server.go:745 +0x24
created by github.com/anacrolix/dht/v2.(*traversal).run
@anacrolix
Copy link
Owner

Could you try the associated commit? Was this issue only present on arm, did you find anything else that didn't work?

I would welcome PRs to include CI for testing arm if you're interested.

@anacrolix
Copy link
Owner

go get github.com/anacrolix/dht/v2@fd60ad06b4827d42a76235103e88b20e633db27c should do what you need in your project for testing this.

@compliment
Copy link
Author

Was this issue only present on arm?

According to atomic/#pkg-note-BUG it affects all 32-bit architectures. I can confirm the same on ARM and 386.

anacrolix/dht@fd60ad0 didn't fix it, same error with different line number.

example/torrent built for 386

panic: unaligned 64-bit atomic operation

goroutine 795 [running]:
runtime/internal/atomic.panicUnaligned()
	runtime/internal/atomic/unaligned.go:8 +0x2d
runtime/internal/atomic.Xadd64(0x9e321e4, 0x1, 0x0, 0x0, 0x0)
	runtime/internal/atomic/asm_386.s:107 +0x11
github.com/anacrolix/dht/v2.(*traversal).wrapQuery(0x9e321e4, 0x86c4250, 0x9c753c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	github.com/anacrolix/dht/v2@v2.9.2-0.20210509011734-fd60ad06b482/traversal.go:115 +0x52
github.com/anacrolix/dht/v2.(*traversal).run.func1.1(0x9c0e008)
	github.com/anacrolix/dht/v2@v2.9.2-0.20210509011734-fd60ad06b482/traversal.go:156 +0x35
github.com/anacrolix/dht/v2.(*traversal).beginQuery.func1.1(0x0)
	github.com/anacrolix/dht/v2@v2.9.2-0.20210509011734-fd60ad06b482/traversal.go:179 +0x93
github.com/anacrolix/dht/v2.(*Server).beginQuery.func1.1()
	github.com/anacrolix/dht/v2@v2.9.2-0.20210509011734-fd60ad06b482/server.go:745 +0x23
created by github.com/anacrolix/dht/v2.(*traversal).run
	github.com/anacrolix/dht/v2@v2.9.2-0.20210509011734-fd60ad06b482/traversal.go:164 +0x83

@compliment compliment changed the title panic: unaligned 64-bit atomic operation. Support arm too. panic: unaligned 64-bit atomic operation. Support 32-bit architectures too. May 9, 2021
@anacrolix
Copy link
Owner

Could you provide the new stack trace? It's probably another atomic elsewhere in the package that also needs to be fixed.

@compliment
Copy link
Author

compliment commented May 9, 2021

@anacrolix You can build example/torrent from this repo itself for linux 386 and run it on amd64 or for linux arm and run it on arm64. I included the new stack trace for example/torrent from this repo itself in the previous comment.

@anacrolix
Copy link
Owner

Sorry I don't have the necessary platforms available. A PR to include those in CI is welcomed. It should be sufficient to move any stat blocks to the top of their structs, per some of the comments where I've done this previously.

@silentmurdock
Copy link

silentmurdock commented May 22, 2021

Hello!

I think I've managed to fix the problem with the help of this page: https://go101.org/article/memory-layout.html
I made a pull request for the dht v2.9.1 package.

I use anacrolix torrent for my torrent player application ( White Raven ) for Samsung Smart TV E, F, H series. Each of these televisions has armv7 and armv6 32-bit processors.

For me, this bug fix is necessary.

Tested on armv7 32-bit, windows 32-bit, linux 32-bit.

@anacrolix
Copy link
Owner

Interesting article. I take it then on a 32 bit system, the struct field alignment even of an int64 might be only 4 bytes.

@anacrolix
Copy link
Owner

See anacrolix/dht#46.

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

3 participants