2
0

Fix: Resource.Destroy removed self from pool after destructor complete

This commit is contained in:
Jack Christensen
2020-08-20 21:56:47 -05:00
parent 6706e16fc2
commit 6d0ef02e90
3 changed files with 15 additions and 6 deletions
+2 -4
View File
@@ -64,7 +64,7 @@ func (res *Resource) Destroy() {
if res.status != resourceStatusAcquired {
panic("tried to destroy resource that is not acquired")
}
res.pool.destroyAcquiredResource(res)
go res.pool.destroyAcquiredResource(res)
}
// Hijack assumes ownership of the resource from the pool. Caller is responsible
@@ -435,11 +435,9 @@ func (p *Pool) releaseAcquiredResource(res *Resource, lastUsedNano int64) {
// Remove removes res from the pool and closes it. If res is not part of the
// pool Remove will panic.
func (p *Pool) destroyAcquiredResource(res *Resource) {
p.destructResourceValue(res.value)
p.cond.L.Lock()
p.allResources = removeResource(p.allResources, res)
go p.destructResourceValue(res.value)
p.cond.L.Unlock()
p.cond.Signal()
}