Skip to content

Commit 6f2fddb

Browse files
authored
Merge pull request #768 from gingersamurai/master
made closing connections parallel
2 parents c13f0c6 + f36797b commit 6f2fddb

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

internal/conn/pool.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package conn
22

33
import (
44
"context"
5+
"sync"
56
"sync/atomic"
67
"time"
78

@@ -137,11 +138,26 @@ func (p *Pool) Release(ctx context.Context) error {
137138
}
138139
})
139140

140-
var issues []error
141+
var (
142+
errCh = make(chan error, len(conns))
143+
wg sync.WaitGroup
144+
)
145+
146+
wg.Add(len(conns))
141147
for _, c := range conns {
142-
if err := c.Close(ctx); err != nil {
143-
issues = append(issues, err)
144-
}
148+
go func(c closer.Closer) {
149+
defer wg.Done()
150+
if err := c.Close(ctx); err != nil {
151+
errCh <- err
152+
}
153+
}(c)
154+
}
155+
wg.Wait()
156+
close(errCh)
157+
158+
issues := make([]error, 0, len(conns))
159+
for err := range errCh {
160+
issues = append(issues, err)
145161
}
146162

147163
if len(issues) > 0 {

0 commit comments

Comments
 (0)