Skip to content

Commit

Permalink
Fix(atomic panic): 64-bit fields must be 64-bit aligned on 32-bit sys…
Browse files Browse the repository at this point in the history
…tems (#358)
  • Loading branch information
Loyalsoldier authored Jun 3, 2021
1 parent 7f8d638 commit 068d233
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
18 changes: 12 additions & 6 deletions statistic/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ import (
const Name = "MEMORY"

type User struct {
sent uint64
recv uint64
lastSent uint64
lastRecv uint64
sendSpeed uint64
recvSpeed uint64
// WARNING: do not change the order of these fields.
// 64-bit fields that use `sync/atomic` package functions
// must be 64-bit aligned on 32-bit systems.
// Reference: https://github.com/golang/go/issues/599
// Solution: https://github.com/golang/go/issues/11891#issuecomment-433623786
sent uint64
recv uint64
lastSent uint64
lastRecv uint64
sendSpeed uint64
recvSpeed uint64

hash string
ipTable sync.Map
ipNum int32
Expand Down
10 changes: 8 additions & 2 deletions tunnel/trojan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ const (
)

type OutboundConn struct {
// WARNING: do not change the order of these fields.
// 64-bit fields that use `sync/atomic` package functions
// must be 64-bit aligned on 32-bit systems.
// Reference: https://github.com/golang/go/issues/599
// Solution: https://github.com/golang/go/issues/11891#issuecomment-433623786
sent uint64
recv uint64

metadata *tunnel.Metadata
sent uint64
recv uint64
user statistic.User
headerWrittenOnce sync.Once
net.Conn
Expand Down
10 changes: 8 additions & 2 deletions tunnel/trojan/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ import (

// InboundConn is a trojan inbound connection
type InboundConn struct {
// WARNING: do not change the order of these fields.
// 64-bit fields that use `sync/atomic` package functions
// must be 64-bit aligned on 32-bit systems.
// Reference: https://github.com/golang/go/issues/599
// Solution: https://github.com/golang/go/issues/11891#issuecomment-433623786
sent uint64
recv uint64

net.Conn
sent uint64
recv uint64
auth statistic.Authenticator
user statistic.User
hash string
Expand Down

0 comments on commit 068d233

Please sign in to comment.