From 068d23371c2676212a3399edbabfb2aaedf63750 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Thu, 3 Jun 2021 11:00:44 +0800 Subject: [PATCH] Fix(atomic panic): 64-bit fields must be 64-bit aligned on 32-bit systems (#358) --- statistic/memory/memory.go | 18 ++++++++++++------ tunnel/trojan/client.go | 10 ++++++++-- tunnel/trojan/server.go | 10 ++++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/statistic/memory/memory.go b/statistic/memory/memory.go index d1b96115a..0147bf1f6 100644 --- a/statistic/memory/memory.go +++ b/statistic/memory/memory.go @@ -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 diff --git a/tunnel/trojan/client.go b/tunnel/trojan/client.go index 778245d63..561d95dee 100644 --- a/tunnel/trojan/client.go +++ b/tunnel/trojan/client.go @@ -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 diff --git a/tunnel/trojan/server.go b/tunnel/trojan/server.go index 52e46cc38..d30810a17 100644 --- a/tunnel/trojan/server.go +++ b/tunnel/trojan/server.go @@ -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