Skip to content

Commit

Permalink
Fix unaligned load error on 32-bit architectures
Browse files Browse the repository at this point in the history
On some 32-bit architectures, 64-bit atomic operations panic when the
value is not aligned properly.

In this package, this causes netConn operations to panic when compiling
with GOARCH=386, since netConn does atomic operations with int64 values
in the netConn struct (namely, with readExpired and writeExpired).

This commit fixes this by moving readExpired and writeExpired to the
beginning of the struct, which makes them properly aligned.
  • Loading branch information
x0wllaar committed Feb 26, 2024
1 parent e3a2d32 commit 4c27331
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions netconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,23 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
}

type netConn struct {
readExpired int64
writeExpired int64

c *Conn
msgType MessageType

writeTimer *time.Timer
writeMu *mu
writeExpired int64
writeCtx context.Context
writeCancel context.CancelFunc

readTimer *time.Timer
readMu *mu
readExpired int64
readCtx context.Context
readCancel context.CancelFunc
readEOFed bool
reader io.Reader
writeTimer *time.Timer
writeMu *mu
writeCtx context.Context
writeCancel context.CancelFunc

readTimer *time.Timer
readMu *mu
readCtx context.Context
readCancel context.CancelFunc
readEOFed bool
reader io.Reader
}

var _ net.Conn = &netConn{}
Expand Down

0 comments on commit 4c27331

Please sign in to comment.