removeConn removes a connection from the pool's internal data structures. Returns true if the connection was present and removed, false otherwise.
(cn *Conn)
| 1506 | // removeConn removes a connection from the pool's internal data structures. |
| 1507 | // Returns true if the connection was present and removed, false otherwise. |
| 1508 | func (p *ConnPool) removeConn(cn *Conn) bool { |
| 1509 | cid := cn.GetID() |
| 1510 | if _, exists := p.conns[cid]; !exists { |
| 1511 | return false |
| 1512 | } |
| 1513 | delete(p.conns, cid) |
| 1514 | atomic.AddUint32(&p.stats.StaleConns, 1) |
| 1515 | |
| 1516 | // Decrement pool size counter when removing a connection |
| 1517 | if cn.pooled { |
| 1518 | p.poolSize.Add(-1) |
| 1519 | // this can be idle conn |
| 1520 | for idx, ic := range p.idleConns { |
| 1521 | if ic == cn { |
| 1522 | p.idleConns = append(p.idleConns[:idx], p.idleConns[idx+1:]...) |
| 1523 | p.idleConnsLen.Add(-1) |
| 1524 | break |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | return true |
| 1529 | } |
| 1530 | |
| 1531 | func (p *ConnPool) closeConn(cn *Conn) error { |
| 1532 | return cn.Close() |
no test coverage detected