mirror of https://github.com/go-redis/redis.git
newConn race fix
This commit is contained in:
parent
5aa430d974
commit
d8227214bc
|
@ -164,6 +164,18 @@ func (p *ConnPool) NewConn(ctx context.Context) (*Conn, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) {
|
func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) {
|
||||||
|
var poolExhausted bool
|
||||||
|
|
||||||
|
p.connsMu.Lock()
|
||||||
|
if p.cfg.MaxActiveConns > 0 {
|
||||||
|
poolExhausted = p.poolSize >= p.cfg.MaxActiveConns
|
||||||
|
}
|
||||||
|
p.connsMu.Unlock()
|
||||||
|
|
||||||
|
if poolExhausted {
|
||||||
|
return nil, ErrPoolExhausted
|
||||||
|
}
|
||||||
|
|
||||||
cn, err := p.dialConn(ctx, pooled)
|
cn, err := p.dialConn(ctx, pooled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -178,12 +190,6 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) {
|
||||||
return nil, ErrClosed
|
return nil, ErrClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not allowed to add new connections to the connection pool.
|
|
||||||
if p.cfg.MaxActiveConns > 0 && p.poolSize >= p.cfg.MaxActiveConns {
|
|
||||||
_ = cn.Close()
|
|
||||||
return nil, ErrPoolExhausted
|
|
||||||
}
|
|
||||||
|
|
||||||
p.conns = append(p.conns, cn)
|
p.conns = append(p.conns, cn)
|
||||||
if pooled {
|
if pooled {
|
||||||
// If pool is full remove the cn on next Put.
|
// If pool is full remove the cn on next Put.
|
||||||
|
|
Loading…
Reference in New Issue