From 90b69c0ee006e7b43097cd393d0ccf31aaa02766 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 27 Aug 2022 09:23:17 -0500 Subject: [PATCH] Fix atomic alignment on 32-bit platforms refs #1288 --- pgxpool/pool.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pgxpool/pool.go b/pgxpool/pool.go index cd13be55..236ba000 100644 --- a/pgxpool/pool.go +++ b/pgxpool/pool.go @@ -72,6 +72,12 @@ func (cr *connResource) getPoolRows(c *Conn, r pgx.Rows) *poolRows { // Pool allows for connection reuse. type Pool 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. + newConnsCount int64 + lifetimeDestroyCount int64 + idleDestroyCount int64 + p *puddle.Pool[*connResource] config *Config beforeConnect func(context.Context, *pgx.ConnConfig) error @@ -87,10 +93,6 @@ type Pool struct { healthCheckChan chan struct{} - newConnsCount int64 - lifetimeDestroyCount int64 - idleDestroyCount int64 - closeOnce sync.Once closeChan chan struct{} }