mirror of https://github.com/jackc/pgx.git
ConnPool.Close does not wait for acquired conns
parent
0cda099bb5
commit
0a67735a8e
18
conn_pool.go
18
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
|
||||
|
|
2
v3.md
2
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
|
||||
|
|
Loading…
Reference in New Issue