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 return false
} }
// Close ends the use of a connection pool. It prevents any new connections // Close ends the use of a connection pool. It prevents any new connections from
// from being acquired, waits until all acquired connections are released, // being acquired and closes available underlying connections. Any acquired
// then closes all underlying connections. // connections will be closed when they are released.
func (p *ConnPool) Close() { func (p *ConnPool) Close() {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
p.closed = true p.closed = true
// Wait until all connections are released for _, c := range p.availableConnections {
if len(p.availableConnections) != len(p.allConnections) {
for len(p.availableConnections) != len(p.allConnections) {
p.cond.Wait()
}
}
for _, c := range p.allConnections {
_ = c.Close() _ = 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 // 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 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 ## TODO / Possible / Investigate
Organize errors better Organize errors better