2
0

Fix goroutine leak

This commit is contained in:
Jan Dubsky
2022-09-30 13:46:09 +02:00
committed by Jack Christensen
parent 58f94f0470
commit 93a3f7de51
+8 -3
View File
@@ -355,11 +355,16 @@ func (p *Pool[T]) acquire(ctx context.Context) (*Resource[T], error) {
if err != nil {
p.allResources = removeResource(p.allResources, res)
p.destructWG.Done()
constructErrCh <- err
p.cond.L.Unlock()
p.cond.Signal()
select {
case constructErrCh <- err:
case <-ctx.Done():
// The caller is cancelled, so
// no-one awaits the error. This
// branch avoid goroutine leak.
}
return
}