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

Unexpected cancellation - Coil doesn't work with setRetainInstance #1918

Open
darrentaft opened this issue Nov 9, 2023 · 5 comments
Open
Labels
help wanted Issues that are up for grabs + are good candidates for community PRs

Comments

@darrentaft
Copy link

When setRetainInstance is true on a fragment, coil refuses to load any images after configuration change. Logs indicate that all the requests are cancelled, as the Coroutine scope is blindly cancelled from onConfigurationChanged.

I suspect this will be marked as WillNotFix as setRetainInstance is deprecated and strongly advised against - we have it in some legacy code that I have now started to refactor as a result of this bug.

Raising here for awareness and to save anyone else potentially spending hours investigating this.

Using Coil 2.5.0

@colinrtwhite
Copy link
Member

Are all new requests cancelled if they're launched after the view is reattached to the activity? If you use an ImageView attached to a fragment, that fragment must be attached to an activity or the request will be cancelled. If we allowed requests to proceed on detached fragments that's likely to leak the view reference.

@darrentaft
Copy link
Author

All requests from the retained fragment are immediately cancelled from the moment the device is rotated. It never recovers - e.g. I scroll the recyclerview up and down, and the image requests are all immediately cancelled.

As far as I could see, the Scope defined in RealImageLoader is cancelled from the shutdown method, which is called from onConfigurationChanged. The scope is never recreated, so all calls to it are immediately cancelled.

@colinrtwhite
Copy link
Member

@darrentaft The scope in RealImageLoader is only cancelled by onConfigurationChanged if the ImageLoader is freed by the GC, which won't occur for the singleton image loader. Are you sure the scope is cancelled? Requests are also cancelled if the fragment's root View is detached, which seems more likely.

@colinrtwhite colinrtwhite added the help wanted Issues that are up for grabs + are good candidates for community PRs label Nov 16, 2023
@darrentaft
Copy link
Author

It's definitely attached - I'm scrolling the RecyclerView up and down the screen, and all image requests (for elements within it) immediately report that they're cancelled. The text elements around the image update correctly.

@eneim
Copy link

eneim commented Jan 4, 2024

@darrentaft Can you share the bit of code using Coil in your Fragment? I'm asking for curiosity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues that are up for grabs + are good candidates for community PRs
Projects
None yet
Development

No branches or pull requests

3 participants