ConnPool.Close does not wait for acquired conns

batch-wip
Jack Christensen 2017-05-06 09:25:58 -05:00
parent 0cda099bb5
commit 0a67735a8e
2 changed files with 9 additions and 11 deletions

View File

@ -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

2
v3.md
View File

@ -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