diff --git a/conn_pool.go b/conn_pool.go index 7bc022d0..6a1f37a2 100644 --- a/conn_pool.go +++ b/conn_pool.go @@ -230,25 +230,21 @@ func (p *ConnPool) removeFromAllConnections(conn *Conn) bool { return false } -// Close ends the use of a connection pool. It prevents any new connections -// from being acquired, waits until all acquired connections are released, -// then closes all underlying connections. +// Close ends the use of a connection pool. It prevents any new connections from +// being acquired and closes available underlying connections. Any acquired +// connections will be closed when they are released. func (p *ConnPool) Close() { p.cond.L.Lock() defer p.cond.L.Unlock() p.closed = true - // Wait until all connections are released - if len(p.availableConnections) != len(p.allConnections) { - for len(p.availableConnections) != len(p.allConnections) { - p.cond.Wait() - } - } - - for _, c := range p.allConnections { + for _, c := range p.availableConnections { _ = c.Close() } + + // This will cause any checked out connections to be closed on release + p.resetCount++ } // Reset closes all open connections, but leaves the pool open. It is intended diff --git a/v3.md b/v3.md index 72110888..d4dfe1bd 100644 --- a/v3.md +++ b/v3.md @@ -36,6 +36,8 @@ Removed ValueReader Replaced Scanner, Encoder, and PgxScanner interfaces with pgtype system +ConnPool.Close no longer waits for all acquired connections to be released. Instead, it immediately closes all available connections, and closes acquired connections when they are released in the same manner as ConnPool.Reset. + ## TODO / Possible / Investigate Organize errors better