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

Crash when clearing the cache while app is in the background #37

Closed
MV-GH opened this issue Jul 31, 2023 · 6 comments
Closed

Crash when clearing the cache while app is in the background #37

MV-GH opened this issue Jul 31, 2023 · 6 comments
Assignees

Comments

@MV-GH
Copy link

MV-GH commented Jul 31, 2023

When having my app in the background and then clearing the cache through appinfo in android settings. Upon entering the app and selecting a image (which creates a ZoomableAsyncImage), it crashes. Other than that your library has been working great!

Version: 1.0.0-alpha02

stacktrace FATAL EXCEPTION: main Process: com.jerboa, PID: 8240 java.lang.IllegalStateException: Coil returned a null image from disk cache at me.saket.telephoto.zoomable.coil.Resolver.work(Unknown Source:245) at me.saket.telephoto.zoomable.coil.Resolver$work$1.invokeSuspend(Unknown Source:11) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8) at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Unknown Source:6) at kotlinx.coroutines.AbstractCoroutine.resumeWith(Unknown Source:22) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:31) at kotlinx.coroutines.DispatchedTask.run(Unknown Source:109) at kotlinx.coroutines.EventLoopImplPlatform.processUnconfinedEvent(Unknown Source:23) at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(Unknown Source:116) at kotlinx.coroutines.CancellableContinuationImpl.completeResume(Unknown Source:2) at kotlinx.coroutines.channels.BufferedChannelKt.tryResume0(Unknown Source:6) at kotlinx.coroutines.channels.BufferedChannel.tryResumeReceiver(Unknown Source:94) at kotlinx.coroutines.channels.BufferedChannel.access$updateCellSend(Unknown Source:51) at kotlinx.coroutines.channels.BufferedChannel.trySend-JP2dKIU(Unknown Source:107) at androidx.compose.runtime.Recomposer$recompositionRunner$2$unregisterApplyObserver$1.invoke(SourceFile:12) at androidx.compose.runtime.Recomposer$recompositionRunner$2$unregisterApplyObserver$1.invoke(SourceFile:2) at androidx.compose.runtime.snapshots.SnapshotKt.advanceGlobalSnapshot(Unknown Source:73) at androidx.compose.material.Strings$Companion.sendApplyNotifications(Unknown Source:29) at androidx.compose.ui.platform.GlobalSnapshotManager$ensureStarted$1.invokeSuspend(Unknown Source:73) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8) at kotlinx.coroutines.DispatchedTask.run(Unknown Source:109) at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(Unknown Source:22) at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7842) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@921ce6a, Dispatchers.Main.immediate]
@saket
Copy link
Owner

saket commented Aug 1, 2023

Hmm if coil says it still has images in its disk cache even after the cache is cleared then I'm afraid I can't do anything here. Wanna recreate this issue on https://github.com/coil-kt/coil/issues instead?

@MV-GH
Copy link
Author

MV-GH commented Aug 1, 2023

I'll see if I can reproduce this with AsyncImage and then I'll make an issue on coil repo.

@saket
Copy link
Owner

saket commented Aug 2, 2023

I think this is slightly difficult to reproduce with AsyncImage because it will skip its disk cache when images are cached in memory. Telephoto, on the other hand, can't read from memory. It assumes that images are always available on disk because it sets coil's diskCachePolicy to CachePolicy.ENABLED.

@colinrtwhite would you have any ideas on how I can handle this? Coil does not re-write images to the disk cache when they're read from the memory. Could Coil detect if its disk cache was deleted and maybe bust its memory cache?

@colinrtwhite
Copy link

colinrtwhite commented Aug 2, 2023

@saket Hmm this is a tough one. I don't think we want to clear an item from the memory cache if it's been removed from the disk cache because:

  • This reduces the memory cache hit rate, which we want to maximize.
  • This would require us to perform a disk cache read on the main thread for every memory cache hit, which would be slow.

My first instinct to handle this would be to:

  • Perform a request as usual.
  • If diskCache.openSnapshot(diskCacheKey) is null, handle it gracefully by retrying the request with memoryCachePolicy(CachePolicy.DISABLED) to skip the memory cache.
  • If diskCache.openSnapshot(diskCacheKey) is still null then log an error.

Overall, I'd avoid using !! with diskCache.openSnapshot(diskCacheKey) as there are other cases where it's not possible to open a snapshot for an entry (cache corruption, someone else already opened an Editor for that key, etc.).

@Hospes
Copy link

Hospes commented Aug 17, 2023

Hey guys, I have this kind of crash in crash reporting also. It's not very often but anyway it happens. I would like to have some fix for that. 💯

@saket
Copy link
Owner

saket commented Apr 28, 2024

Took me a while, but this should be fixed by v0.11.2. ZoomableAsyncImage() will now reload images if the disk cache is found empty before throwing an error, as suggested by @colinrtwhite.

github-merge-queue bot pushed a commit to slackhq/circuit that referenced this issue Apr 28, 2024
…1373)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[me.saket.telephoto:zoomable-image-coil](https://togithub.com/saket/telephoto)
| dependencies | minor | `0.10.0` -> `0.11.2` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>saket/telephoto
(me.saket.telephoto:zoomable-image-coil)</summary>

###
[`v0.11.2`](https://togithub.com/saket/telephoto/releases/tag/0.11.2)

Bug fixes

-
[saket/telephoto#84:
Fixed an issue causing placeholders to sometimes take up the full screen
(by [@&#8203;rharter](https://togithub.com/rharter))
-
[saket/telephoto#37:
Prevent a crash in `ZoomableAsyncImage()` after the app's disk cache is
cleared
-
[saket/telephoto#83:
Correctly display single-frame GIFs

New changes

- Increase memory cache hit rate with Coil by using `Precision.INEXACT`

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **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.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjYuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMyNi4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
ZacSweers pushed a commit to ZacSweers/CatchUp that referenced this issue Apr 29, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[me.saket.telephoto:zoomable-image-coil](https://togithub.com/saket/telephoto)
| `0.10.0` -> `0.11.2` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/me.saket.telephoto:zoomable-image-coil/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/me.saket.telephoto:zoomable-image-coil/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/me.saket.telephoto:zoomable-image-coil/0.10.0/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/me.saket.telephoto:zoomable-image-coil/0.10.0/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
|
[me.saket.telephoto:zoomable-image](https://togithub.com/saket/telephoto)
| `0.10.0` -> `0.11.2` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/me.saket.telephoto:zoomable-image/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/me.saket.telephoto:zoomable-image/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/me.saket.telephoto:zoomable-image/0.10.0/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/me.saket.telephoto:zoomable-image/0.10.0/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [me.saket.telephoto:zoomable](https://togithub.com/saket/telephoto) |
`0.10.0` -> `0.11.2` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/me.saket.telephoto:zoomable/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/me.saket.telephoto:zoomable/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/me.saket.telephoto:zoomable/0.10.0/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/me.saket.telephoto:zoomable/0.10.0/0.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>saket/telephoto
(me.saket.telephoto:zoomable-image-coil)</summary>

###
[`v0.11.2`](https://togithub.com/saket/telephoto/releases/tag/0.11.2)

Bug fixes

-
[saket/telephoto#84:
Fixed an issue causing placeholders to sometimes take up the full screen
(by [@&#8203;rharter](https://togithub.com/rharter))
-
[saket/telephoto#37:
Prevent a crash in `ZoomableAsyncImage()` after the app's disk cache is
cleared
-
[saket/telephoto#83:
Correctly display single-frame GIFs

New changes

- Increase memory cache hit rate with Coil by using `Precision.INEXACT`

</details>

---

### 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 these
updates again.

---

- [ ] <!-- rebase-check -->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/ZacSweers/CatchUp).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMyMS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
ibabuk added a commit to ibabuk/telephoto that referenced this issue May 24, 2024
* trunk: (45 commits)
  Prepare next development version
  Prepare to release v0.11.2
  Reload images using coil only once
  Revert the version to 0.10.0 on project website
  Set coil's precision to INEXACT only if it wasn't explicitly set
  Abort v0.11.0's release
  Prepare to release v0.11.0
  Re-enable death penalty for leaking closable object violations
  Fix typos in SubSamplingImageSource#canBeSubSampled()
  Fix a DiskReadViolation when reading file headers
  Reload an image if its deleted from disk cache
  Add a failing test for saket#37
  Increase memory cache hit rate with Coil
  Fail fast if screenshot tests are run on an incompatible device
  Move the test for async placeholders to ZoomableImageTest
  Add a test to verify single-frame GIFs with glide
  Prevent sub-sampling of single-frame GIFs
  Add a failing test to reproduce saket#83
  Updates test to use existing imagery.
  Updates test name
  ...

# Conflicts:
#	gradle/libs.versions.toml
#	test-util/src/main/kotlin/me/saket/telephoto/util/prepareActivity.kt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants