mirror of https://github.com/go-redis/redis.git
Merge pull request #119 from go-redis/fix/panic-when-list-closed
Don't panic if list is closed and conn can't be found.
This commit is contained in:
commit
2c4f6f8a2c
24
pool.go
24
pool.go
|
@ -80,6 +80,9 @@ func (l *connList) Remove(cn *conn) error {
|
|||
}
|
||||
}
|
||||
|
||||
if l.closed() {
|
||||
return nil
|
||||
}
|
||||
panic("conn not found in the list")
|
||||
}
|
||||
|
||||
|
@ -94,6 +97,9 @@ func (l *connList) Replace(cn, newcn *conn) error {
|
|||
}
|
||||
}
|
||||
|
||||
if l.closed() {
|
||||
return newcn.Close()
|
||||
}
|
||||
panic("conn not found in the list")
|
||||
}
|
||||
|
||||
|
@ -110,6 +116,10 @@ func (l *connList) Close() (retErr error) {
|
|||
return retErr
|
||||
}
|
||||
|
||||
func (l *connList) closed() bool {
|
||||
return l.cns == nil
|
||||
}
|
||||
|
||||
type connPool struct {
|
||||
dialer func() (*conn, error)
|
||||
|
||||
|
@ -245,11 +255,6 @@ func (p *connPool) Put(cn *conn) error {
|
|||
}
|
||||
|
||||
func (p *connPool) Remove(cn *conn) error {
|
||||
if p.closed() {
|
||||
// Close already closed all connections.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Replace existing connection with new one and unblock waiter.
|
||||
newcn, err := p.new()
|
||||
if err != nil {
|
||||
|
@ -372,12 +377,6 @@ func (p *singleConnPool) Put(cn *conn) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *singleConnPool) put() error {
|
||||
err := p.pool.Put(p.cn)
|
||||
p.cn = nil
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *singleConnPool) Remove(cn *conn) error {
|
||||
defer p.cnMtx.Unlock()
|
||||
p.cnMtx.Lock()
|
||||
|
@ -427,7 +426,8 @@ func (p *singleConnPool) Close() error {
|
|||
var err error
|
||||
if p.cn != nil {
|
||||
if p.reusable {
|
||||
err = p.put()
|
||||
err = p.pool.Put(p.cn)
|
||||
p.cn = nil
|
||||
} else {
|
||||
err = p.remove()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue