Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource cache fails to complete future exceptionally & throws unhandled coroutine exception #3098

Closed
rli opened this issue Mar 11, 2022 · 1 comment
Labels
bug We can reproduce the issue and confirmed it is a bug.

Comments

@rli
Copy link
Contributor

rli commented Mar 11, 2022

private fun <T> getCachedResource(context: Context<T>) {
ApplicationManager.getApplication().executeOnPooledThread {
var currentValue: Entry<T>? = null
try {
@Suppress("UNCHECKED_CAST")
val result = cache.compute(context.cacheKey) { _, value ->
currentValue = value as Entry<T>?
fetchIfNeeded(context, currentValue)
} as Entry<T>
coroutineScope.launch {
try {
context.future.complete(result.value.await())
} catch (e: Throwable) {
val deferred = currentValue
if (context.useStale && deferred != null && deferred.value.isCompleted) {
context.future.complete(deferred.value.getCompleted())
} else {
context.future.completeExceptionally(e)
}
}
}

L320 in DefaultAwsResourceCache can return a cached entry where the deferred value has completed exceptionally. As a result, result.value.await() (L325) throws, is caught by the surrounding block, and is unhandled due to the deferred.value.getCompleted() call on (L329).

Reproducable by doing a cache.getResource() call that throws the first time(successfully bubbles out to callee code), but the second call will trigger the bug

@rli rli added the bug We can reproduce the issue and confirmed it is a bug. label Mar 11, 2022
@rli
Copy link
Contributor Author

rli commented Jun 1, 2022

Released in 1.44

@rli rli closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug We can reproduce the issue and confirmed it is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant