mirror of https://github.com/go-redis/redis.git
pool: close all connections at once.
This commit is contained in:
parent
fc04a09033
commit
7d886330f1
12
pool.go
12
pool.go
|
@ -278,17 +278,13 @@ func (p *connPool) Close() (retErr error) {
|
||||||
if !atomic.CompareAndSwapInt32(&p._closed, 0, 1) {
|
if !atomic.CompareAndSwapInt32(&p._closed, 0, 1) {
|
||||||
return errClosed
|
return errClosed
|
||||||
}
|
}
|
||||||
// First close free connections.
|
// Wait for app to free connections, but don't close them immediately.
|
||||||
for p.Len() > 0 {
|
for i := 0; i < p.Len(); i++ {
|
||||||
cn := p.wait()
|
if cn := p.wait(); cn == nil {
|
||||||
if cn == nil {
|
|
||||||
break
|
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 {
|
if err := p.conns.Close(); err != nil {
|
||||||
retErr = err
|
retErr = err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue