From 4d5f8a5df319a6561b3d48eec4c00d86b06e65df Mon Sep 17 00:00:00 2001 From: wanglei6 Date: Thu, 30 Apr 2020 14:34:48 +0800 Subject: [PATCH 1/2] fix data race --- internal/pool/pool.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/pool/pool.go b/internal/pool/pool.go index bbf5b30..36f6953 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -93,8 +93,9 @@ func NewConnPool(opt *Options) *ConnPool { idleConns: make([]*Conn, 0, opt.PoolSize), closedCh: make(chan struct{}), } - + p.connsMu.Lock() p.checkMinIdleConns() + p.connsMu.Unlock() if opt.IdleTimeout > 0 && opt.IdleCheckFrequency > 0 { go p.reaper(opt.IdleCheckFrequency) From 39881392de68490fee9488ae5eb57e5295237c16 Mon Sep 17 00:00:00 2001 From: wanglei6 Date: Thu, 30 Apr 2020 17:46:50 +0800 Subject: [PATCH 2/2] code fmt --- internal/pool/pool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 36f6953..a8d8276 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -93,6 +93,7 @@ func NewConnPool(opt *Options) *ConnPool { idleConns: make([]*Conn, 0, opt.PoolSize), closedCh: make(chan struct{}), } + p.connsMu.Lock() p.checkMinIdleConns() p.connsMu.Unlock()