Skip to content

Commit

Permalink
Close the factory under the SingleObjectPool lock to avoid racing on …
Browse files Browse the repository at this point in the history
…creation when closing the pool.

Signed-off-by: Kenneth J. Shackleton <[email protected]>
  • Loading branch information
kennethshackleton committed Jul 7, 2021
1 parent 329b932 commit 3c0ac40
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class SingleObjectPool<K : Any, T : IPooledObject<K>>(
override fun returnObject(obj: T) {
canEvict = false
if (isClosed) {
evictThenUnlock()
processCloseThenUnlock()
} else {
mutex.unlock()
}
Expand All @@ -75,12 +75,11 @@ internal class SingleObjectPool<K : Any, T : IPooledObject<K>>(

internal fun evict(priority: Priority? = null) = mutex.run {
when {
isClosed -> {
isClosed -> withTryLock {
factory.close()
evictions(null)
}.also {
attemptUnparkWaiters()
withTryLock {
evictions(null)
}
}
priority.isHigh() -> withTryLock {
evictions(priority)
Expand Down Expand Up @@ -141,8 +140,9 @@ internal class SingleObjectPool<K : Any, T : IPooledObject<K>>(
}
}

private fun evictThenUnlock() {
private fun processCloseThenUnlock() {
try {
factory.close()
evictions(null)
} finally {
mutex.unlock()
Expand Down

0 comments on commit 3c0ac40

Please sign in to comment.