From 12040b90fbe5a2f540b3016333e2408245a822e4 Mon Sep 17 00:00:00 2001 From: Christophe Beyls Date: Sun, 14 Jul 2024 09:01:01 +0200 Subject: [PATCH 1/2] fix: RequestBuilder.submitAsync() throwing an Exception if the Glide request is restarted (#4569) This is the third attempt to fix `RequestBuilder.submitAsync()`. For the rationale, see the comments of #4436. We now clear the continuation reference after resuming it, to make sure that: 1) It will only be resumed once 2) It will not leak the coroutine when Glide keeps the `Request` around. --- .../tusky/util/GlideExtensions.kt | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/util/GlideExtensions.kt b/app/src/main/java/com/keylesspalace/tusky/util/GlideExtensions.kt index 01629c731..a328a8e7c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/GlideExtensions.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/GlideExtensions.kt @@ -5,6 +5,7 @@ import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target +import kotlin.coroutines.Continuation import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlinx.coroutines.suspendCancellableCoroutine @@ -17,32 +18,41 @@ suspend fun RequestBuilder.submitAsync( height: Int = Target.SIZE_ORIGINAL ): R { return suspendCancellableCoroutine { continuation -> - val target = addListener( - object : RequestListener { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target, - isFirstResource: Boolean - ): Boolean { - continuation.resumeWithException(e ?: GlideException("Image loading failed")) - return false - } - - override fun onResourceReady( - resource: R & Any, - model: Any, - target: Target?, - dataSource: DataSource, - isFirstResource: Boolean - ): Boolean { - if (target?.request?.isComplete == true) { - continuation.resume(resource) - } - return false - } - } - ).submit(width, height) + val target = addListener(ContinuationRequestListener(continuation)) + .submit(width, height) continuation.invokeOnCancellation { target.cancel(true) } } } + +private class ContinuationRequestListener(continuation: Continuation) : RequestListener { + private var continuation: Continuation? = continuation + + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target, + isFirstResource: Boolean + ): Boolean { + continuation?.let { + continuation = null + it.resumeWithException(e ?: GlideException("Image loading failed")) + } + return false + } + + override fun onResourceReady( + resource: R & Any, + model: Any, + target: Target?, + dataSource: DataSource, + isFirstResource: Boolean + ): Boolean { + continuation?.let { + if (target?.request?.isComplete == true) { + continuation = null + it.resume(resource) + } + } + return false + } +} From 1390e078d3ea05e33b839d4650c3ff00329f412a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 14 Jul 2024 09:02:19 +0200 Subject: [PATCH 2/2] Update dependency com.google.truth:truth to v1.4.4 (#4570) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.truth:truth](https://togithub.com/google/truth) | `1.4.3` -> `1.4.4` | [![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.truth:truth/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.truth:truth/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.truth:truth/1.4.3/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.truth:truth/1.4.3/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
google/truth (com.google.truth:truth) ### [`v1.4.4`](https://togithub.com/google/truth/releases/tag/v1.4.4) - Annotated the rest of the main package for nullness, and moved the `@NullMarked` annotation from individual classes up to the package to avoid [a warning under `--release 8`](https://togithub.com/google/truth/issues/1320). ([`e107aea`](https://togithub.com/google/truth/commit/e107aeadc)) - Improved the failure message for `matches` to conditionally suggest using `containsMatch`. ([`7e9fc7a`](https://togithub.com/google/truth/commit/7e9fc7aec))
--- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/tuskyapp/Tusky). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- gradle/libs.versions.toml | 2 +- gradle/verification-metadata.xml | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 60e5da0f3..53a0b10e8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -49,7 +49,7 @@ retrofit = "2.11.0" robolectric = "4.13" sparkbutton = "4.2.0" touchimageview = "3.6" -truth = "1.4.3" +truth = "1.4.4" turbine = "1.1.0" unified-push = "2.4.0" xmlwriter = "1.0.4" diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 55379f147..3731b5751 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -4772,6 +4772,14 @@ + + + + + + + + @@ -4782,6 +4790,11 @@ + + + + +