Skip to content

Commit d77423e

Browse files
Ensure MessageServer.ReqID is 8 byte aligned (#2346)
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 <[email protected]>
1 parent 81dd68b commit d77423e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

p2p/server/msgserver.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ type ResponseHandlers struct {
6161
// MessageServer is a request-response multiplexer on top of the p2p layer. it provides a way to register
6262
// message types on top of a protocol and declare request and response handlers. it matches incoming responses to requests.
6363
type MessageServer struct {
64-
log.Log
65-
ReqID uint64 //request id
64+
ReqID uint64 //request id (must be declared first to ensure 8 byte alignment on 32-bit systems, required by atomic operations)
6665
name string //server name
6766
network Service
6867
pendMutex sync.RWMutex
@@ -74,6 +73,7 @@ type MessageServer struct {
7473
workerCount sync.WaitGroup
7574
workerLimiter chan struct{}
7675
exit chan struct{}
76+
log.Log
7777
}
7878

7979
// Service is the subset of method used by MessageServer for p2p communications.

0 commit comments

Comments
 (0)