Skip to content

Commit

Permalink
Merge pull request #134 from kennethshackleton/singleobjectpool-facto…
Browse files Browse the repository at this point in the history
…ry-close-sync

Close the factory under the SingleObjectPool lock
  • Loading branch information
kennethshackleton authored Jul 7, 2021
2 parents 329b932 + 3c0ac40 commit 0c0ba6e
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 0c0ba6e

Please sign in to comment.