diff --git a/pool.go b/pool.go index b5003cc..5d9ea66 100644 --- a/pool.go +++ b/pool.go @@ -402,6 +402,11 @@ func (p *Pool) CreateResource(ctx context.Context) error { } p.cond.L.Lock() + // If closed while constructing resource then destroy it and return an error + if p.closed { + go p.destructResourceValue(res.value) + return ErrClosedPool + } p.allResources = append(p.allResources, res) p.idleResources = append(p.idleResources, res) p.destructWG.Add(1)