Skip to content

Commit

Permalink
fix ConnPool race in newConn
Browse files Browse the repository at this point in the history
  • Loading branch information
os-oc committed Feb 5, 2024
1 parent 2512123 commit b3d1954
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) {
return nil, ErrClosed
}

p.connsMu.Lock()
if p.cfg.MaxActiveConns > 0 && p.poolSize >= p.cfg.MaxActiveConns {
p.connsMu.Unlock()
return nil, ErrPoolExhausted
}
p.connsMu.Unlock()

cn, err := p.dialConn(ctx, pooled)
if err != nil {
Expand Down

0 comments on commit b3d1954

Please sign in to comment.