Skip to content

Commit b35380a

Browse files
committed
safe creation on closed pool
1 parent 08d746c commit b35380a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/pool/pool.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,17 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) {
269269
}
270270

271271
p.connsMu.Lock()
272-
p.conns[cn.GetID()] = cn
273272
defer p.connsMu.Unlock()
273+
if p.closed() {
274+
_ = cn.Close()
275+
return nil, ErrClosed
276+
}
277+
// Check if pool was closed while we were waiting for the lock
278+
if p.conns == nil {
279+
p.conns = make(map[uint64]*Conn)
280+
}
281+
p.conns[cn.GetID()] = cn
282+
274283
if pooled {
275284
// If pool is full remove the cn on next Put.
276285
currentPoolSize := p.poolSize.Load()

0 commit comments

Comments
 (0)