From 7d886330f114b726d3464c59a62e82b2cdfa7adc Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 3 Jun 2015 14:50:43 +0300 Subject: [PATCH] pool: close all connections at once. --- pool.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pool.go b/pool.go index 090270b..301b9e0 100644 --- a/pool.go +++ b/pool.go @@ -278,17 +278,13 @@ func (p *connPool) Close() (retErr error) { if !atomic.CompareAndSwapInt32(&p._closed, 0, 1) { return errClosed } - // First close free connections. - for p.Len() > 0 { - cn := p.wait() - if cn == nil { + // Wait for app to free connections, but don't close them immediately. + for i := 0; i < p.Len(); i++ { + if cn := p.wait(); cn == nil { break } - if err := p.conns.Remove(cn); err != nil { - retErr = err - } } - // Then close the rest. + // Close all connections. if err := p.conns.Close(); err != nil { retErr = err }