From d7c7ddc594209e641b6066b625973e8d7d711142 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 24 Sep 2022 09:23:36 -0500 Subject: [PATCH] Fix Windows 386 atomic usage https://github.com/jackc/pgx/issues/1307 --- internal/nbconn/nbconn.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/nbconn/nbconn.go b/internal/nbconn/nbconn.go index c091ea3f..99688518 100644 --- a/internal/nbconn/nbconn.go +++ b/internal/nbconn/nbconn.go @@ -60,6 +60,11 @@ type Conn interface { // NetConn is a non-blocking net.Conn wrapper. It implements net.Conn. type NetConn struct { + // 64 bit fields accessed with atomics must be at beginning of struct to guarantee alignment for certain 32-bit + // architectures. See BUGS section of https://pkg.go.dev/sync/atomic and https://github.com/jackc/pgx/issues/1288 and + // https://github.com/jackc/pgx/issues/1307. Only access with atomics + closed int64 // 0 = not closed, 1 = closed + conn net.Conn rawConn syscall.RawConn @@ -79,9 +84,6 @@ type NetConn struct { writeDeadlineLock sync.Mutex writeDeadline time.Time - - // Only access with atomics - closed int64 // 0 = not closed, 1 = closed } func NewNetConn(conn net.Conn, fakeNonBlockingIO bool) *NetConn {