Skip to content

Commit c699a45

Browse files
authored
fix(pool): remove conn from idle conns if present (#3546)
1 parent 33c70b2 commit c699a45

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/pool/pool.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,16 @@ func (p *ConnPool) removeConnWithLock(cn *Conn) {
441441
}
442442

443443
func (p *ConnPool) removeConn(cn *Conn) {
444+
// check idleConns and remove it if present
445+
for i, c := range p.idleConns {
446+
if c == cn {
447+
p.idleConns = append(p.idleConns[:i], p.idleConns[i+1:]...)
448+
p.idleConnsLen--
449+
break
450+
}
451+
}
452+
453+
// then check conns and remove it
444454
for i, c := range p.conns {
445455
if c == cn {
446456
p.conns = append(p.conns[:i], p.conns[i+1:]...)
@@ -451,6 +461,7 @@ func (p *ConnPool) removeConn(cn *Conn) {
451461
break
452462
}
453463
}
464+
454465
atomic.AddUint32(&p.stats.StaleConns, 1)
455466
}
456467

0 commit comments

Comments
 (0)