From 6d8db67ef544e1058c6ba21e722dfef8511de154 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 28 Jul 2019 10:53:40 +0300 Subject: [PATCH] Cleanup --- internal/pool/pool.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/pool/pool.go b/internal/pool/pool.go index af62443..d58666a 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -108,24 +108,29 @@ func (p *ConnPool) checkMinIdleConns() { for p.poolSize < p.opt.PoolSize && p.idleConnsLen < p.opt.MinIdleConns { p.poolSize++ p.idleConnsLen++ - go p.addIdleConn() + go func() { + err := p.addIdleConn() + if err != nil { + p.connsMu.Lock() + p.poolSize-- + p.idleConnsLen-- + p.connsMu.Unlock() + } + }() } } -func (p *ConnPool) addIdleConn() { +func (p *ConnPool) addIdleConn() error { cn, err := p.newConn(context.TODO(), true) if err != nil { - p.connsMu.Lock() - p.poolSize-- - p.idleConnsLen-- - p.connsMu.Unlock() - return + return err } p.connsMu.Lock() p.conns = append(p.conns, cn) p.idleConns = append(p.idleConns, cn) p.connsMu.Unlock() + return nil } func (p *ConnPool) NewConn(ctx context.Context) (*Conn, error) {