Skip to content

Commit 3d095fa

Browse files
committed
fix deadlock on conn.Pool.Close
1 parent 731b5e6 commit 3d095fa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

internal/conn/pool.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ func (p *pool) Close(ctx context.Context) error {
7474
close(p.done)
7575

7676
p.mtx.Lock()
77-
defer p.mtx.Unlock()
77+
conns := make([]Conn, 0, len(p.conns))
78+
for _, c := range p.conns {
79+
conns = append(conns, c)
80+
}
81+
p.mtx.Unlock()
7882

7983
var issues []error
80-
for a, c := range p.conns {
84+
for _, c := range conns {
8185
if err := c.Close(ctx); err != nil {
8286
issues = append(issues, err)
8387
}
84-
delete(p.conns, a)
8588
}
8689

8790
if len(issues) > 0 {

0 commit comments

Comments
 (0)