2
0

Fix race condition when CreateResource is called concurrently with Close

WaitGroup.Add(1) cannot be called after WaitGroup.Wait().
This commit is contained in:
Jack Christensen
2020-04-02 22:11:33 -05:00
parent 7cc1dd1985
commit 558756d6c4
+5
View File
@@ -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)