You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expecting cache.get(key) { ... load value here ... } to propagate exceptions to the caller, as documented:
If the suspendable computation throws, the exception will be propagated to the caller.
What happens instead is the coroutine is cancelled and a JobCancellationException is thrown.
try {
val cache = cacheBuilder<String, String>().build()
cache.get("key") { throw IllegalArgumentException("Whoops") }
} catch (t: Throwable) {
// this is a JobCancellationException; expected to be the thrown IllegalArgumentException
println(t)
}
Exception: kotlinx.coroutines.JobCancellationException: TimeoutCoroutine is cancelling; job=TimeoutCoroutine(timeMillis=45000){Cancelling}@609ac453 (this is inside a kotest test)
The text was updated successfully, but these errors were encountered:
cloudshiftchris
changed the title
Cache.get() cancels coroutine
Cache.get() cancels coroutine when exception thrown
Aug 17, 2024
Looking through the tests - they aren't up-to-date wrt cacheBuilder (most use caffeineBuilder) - the test for exception propagation works for caffeineBuilder but fails when changed to cacheBuilder
// from unit test: https://github.com/sksamuel/aedile/blob/8d3ea128b474062dae9ad6b925f3f0c5d748a75d/aedile-core/src/test/kotlin/com/sksamuel/aedile/core/CacheTest.kt#L42
// exception propagation works
val cache = caffeineBuilder<String, String>().build()
shouldThrow<IllegalStateException> {
cache.get("foo") {
error("kapow")
}
}
// using cacheBuilder instead
// exception propagation fails - coroutine is cancelled
val cache2 = cacheBuilder<String, String>().build()
shouldThrow<IllegalStateException> {
cache2.get("foo") {
error("kapow")
}
}
Expecting
cache.get(key) { ... load value here ... }
to propagate exceptions to the caller, as documented:What happens instead is the coroutine is cancelled and a JobCancellationException is thrown.
Exception: kotlinx.coroutines.JobCancellationException: TimeoutCoroutine is cancelling; job=TimeoutCoroutine(timeMillis=45000){Cancelling}@609ac453
(this is inside a kotest test)The text was updated successfully, but these errors were encountered: