This commit is contained in:
Vladimir Mihailenco 2019-07-28 10:53:40 +03:00
parent 6cd6cd828f
commit 6d8db67ef5
1 changed files with 12 additions and 7 deletions

View File

@ -108,24 +108,29 @@ func (p *ConnPool) checkMinIdleConns() {
for p.poolSize < p.opt.PoolSize && p.idleConnsLen < p.opt.MinIdleConns {
p.poolSize++
p.idleConnsLen++
go p.addIdleConn()
}
}
func (p *ConnPool) addIdleConn() {
cn, err := p.newConn(context.TODO(), true)
go func() {
err := p.addIdleConn()
if err != nil {
p.connsMu.Lock()
p.poolSize--
p.idleConnsLen--
p.connsMu.Unlock()
return
}
}()
}
}
func (p *ConnPool) addIdleConn() error {
cn, err := p.newConn(context.TODO(), true)
if err != nil {
return err
}
p.connsMu.Lock()
p.conns = append(p.conns, cn)
p.idleConns = append(p.idleConns, cn)
p.connsMu.Unlock()
return nil
}
func (p *ConnPool) NewConn(ctx context.Context) (*Conn, error) {