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

[Merged by Bors] - Ensure MessageServer.ReqID is 8 byte aligned #2346

Closed
wants to merge 2 commits into from

Conversation

jacquesadit
Copy link
Contributor

@jacquesadit jacquesadit commented Mar 23, 2021

Atomic operations such as atomic.AddUint64 must operate on 64-bit aligned memory when running on 32-bit systems, otherwise a runtime will panic occur. This is a known issue in go and might be addressed in a future release, see golang/go#36606.

Motivation

Using atomic.AddUint64 on non 64 bit aligned address on 32 bit systems results in a runtime panic. The solution is to guarantee the data it operates on is 64 bit aligned. This can be done by defining such fields as the first item in a struct. See #2336.

Closes #2336

Changes

Moving ReqID to the top of MessageServer guarantees 8 byte alignment. See https://go101.org/article/memory-layout.html section The Alignment Requirement for 64-bit Word Atomic Operations for details on why this works.

Test Plan

This was tested on a Raspberry Pi 4B (armv7l) and on linux x86_64 resulting in no breaking changes.

TODO

  • Test changes

DevOps Notes

  • This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
  • This PR does not affect public APIs
  • This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
  • This PR does not make changes to log messages (which monitoring infrastructure may rely on)

Atomic operations such as atomic.AddUint64 must operate on 64-bit aligned memory when running on 32-bit systems, otherwise a runtime will panic occur. This is a known issue in go and might addressed in a future release, see golang/go#36606.
Copy link
Member

@noamnelke noamnelke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and we should merge it, but I worry that this type of issue will recur in the future if we don't have a way to automatically test it. Is there any way you know to test for this issue on a 64-bit system (ideal, since we'd be able to test it on our development machines)? Otherwise I can try to find out if Github actions provides 32-bit systems to test on.

@jacquesadit
Copy link
Contributor Author

jacquesadit commented Apr 6, 2021

I'm not sure how we can create a test that will break on a 64 bit system, the next best thing could be to run a static linter over the whole code base. For example the original issue was found using go staticheck in vscode, see: https://staticcheck.io/docs/checks#SA1027. Perhaps running a linter could be added as a test to the CI system?

@nkryuchkov
Copy link
Contributor

Yes, the staticcheck linter could be added to the CI, however, it doesn't report the SA1027 issues when it is run on 64-bit systems, so we need to run 32-bit code in CI

@nkryuchkov
Copy link
Contributor

bors merge

bors bot pushed a commit that referenced this pull request Jul 13, 2021
Atomic operations such as atomic.AddUint64 must operate on 64-bit aligned memory when running on 32-bit systems, otherwise a runtime will panic occur. This is a known issue in go and might be addressed in a future release, see golang/go#36606.

## Motivation
Using atomic.AddUint64 on non 64 bit aligned address on 32 bit systems results in a runtime panic. The solution is to guarantee the data it operates on is 64 bit aligned. This can be done by defining such fields as the first item in a struct. See #2336.

Closes #2336 

## Changes
Moving ReqID to the top of MessageServer guarantees 8 byte alignment. See https://go101.org/article/memory-layout.html section _The Alignment Requirement for 64-bit Word Atomic Operations_ for details on why this works.

## Test Plan
This was tested on a Raspberry Pi 4B (armv7l) and on linux x86_64 resulting in no breaking changes. 

## TODO
- [ ] Test changes

## DevOps Notes
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Nikita Kryuchkov <nkryuchkov10@gmail.com>
@bors
Copy link

bors bot commented Jul 13, 2021

Build failed:

@nkryuchkov
Copy link
Contributor

bors merge

bors bot pushed a commit that referenced this pull request Jul 13, 2021
Atomic operations such as atomic.AddUint64 must operate on 64-bit aligned memory when running on 32-bit systems, otherwise a runtime will panic occur. This is a known issue in go and might be addressed in a future release, see golang/go#36606.

## Motivation
Using atomic.AddUint64 on non 64 bit aligned address on 32 bit systems results in a runtime panic. The solution is to guarantee the data it operates on is 64 bit aligned. This can be done by defining such fields as the first item in a struct. See #2336.

Closes #2336 

## Changes
Moving ReqID to the top of MessageServer guarantees 8 byte alignment. See https://go101.org/article/memory-layout.html section _The Alignment Requirement for 64-bit Word Atomic Operations_ for details on why this works.

## Test Plan
This was tested on a Raspberry Pi 4B (armv7l) and on linux x86_64 resulting in no breaking changes. 

## TODO
- [ ] Test changes

## DevOps Notes
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Nikita Kryuchkov <nkryuchkov10@gmail.com>
@bors
Copy link

bors bot commented Jul 13, 2021

Build failed:

@nkryuchkov
Copy link
Contributor

bors merge

bors bot pushed a commit that referenced this pull request Jul 13, 2021
Atomic operations such as atomic.AddUint64 must operate on 64-bit aligned memory when running on 32-bit systems, otherwise a runtime will panic occur. This is a known issue in go and might be addressed in a future release, see golang/go#36606.

## Motivation
Using atomic.AddUint64 on non 64 bit aligned address on 32 bit systems results in a runtime panic. The solution is to guarantee the data it operates on is 64 bit aligned. This can be done by defining such fields as the first item in a struct. See #2336.

Closes #2336 

## Changes
Moving ReqID to the top of MessageServer guarantees 8 byte alignment. See https://go101.org/article/memory-layout.html section _The Alignment Requirement for 64-bit Word Atomic Operations_ for details on why this works.

## Test Plan
This was tested on a Raspberry Pi 4B (armv7l) and on linux x86_64 resulting in no breaking changes. 

## TODO
- [ ] Test changes

## DevOps Notes
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Nikita Kryuchkov <nkryuchkov10@gmail.com>
@nkryuchkov
Copy link
Contributor

bors merge-

@bors
Copy link

bors bot commented Jul 13, 2021

Canceled.

@nkryuchkov
Copy link
Contributor

bors merge

bors bot pushed a commit that referenced this pull request Jul 13, 2021
Atomic operations such as atomic.AddUint64 must operate on 64-bit aligned memory when running on 32-bit systems, otherwise a runtime will panic occur. This is a known issue in go and might be addressed in a future release, see golang/go#36606.

## Motivation
Using atomic.AddUint64 on non 64 bit aligned address on 32 bit systems results in a runtime panic. The solution is to guarantee the data it operates on is 64 bit aligned. This can be done by defining such fields as the first item in a struct. See #2336.

Closes #2336 

## Changes
Moving ReqID to the top of MessageServer guarantees 8 byte alignment. See https://go101.org/article/memory-layout.html section _The Alignment Requirement for 64-bit Word Atomic Operations_ for details on why this works.

## Test Plan
This was tested on a Raspberry Pi 4B (armv7l) and on linux x86_64 resulting in no breaking changes. 

## TODO
- [ ] Test changes

## DevOps Notes
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Nikita Kryuchkov <nkryuchkov10@gmail.com>
@bors
Copy link

bors bot commented Jul 13, 2021

Pull request successfully merged into develop.

Build succeeded:

@bors bors bot changed the title Ensure MessageServer.ReqID is 8 byte aligned [Merged by Bors] - Ensure MessageServer.ReqID is 8 byte aligned Jul 13, 2021
@bors bors bot closed this Jul 13, 2021
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.

Runtime panic caused by unaligned memory in arm32 architectures
4 participants