question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fetcher.key() blocks UI thread

See original GitHub issue

Describe the bug

Currently the key() method of Fetchers is called from the UI thread, which results in a StrictMode violation for the FileFetchers. As it uses the .lastModified() method.

https://github.com/coil-kt/coil/blob/master/coil-base/src/main/java/coil/fetch/FileFetcher.kt#L14

To Reproduce

  • Enable StrictMode in your application
  • Load an Image via coil via the normal view.load() syntax
  • StrictMode will complain about this violation
  • The violation is minimal, but in various cases this can get problematic

Expected behavior

  • method should also be called from a IO dispatcher so it will not block the UI thread

Logs/Screenshots

2019-09-12 18:15:20.539 16670-16670 D/StrictMode: StrictMode policy violation; ~duration=1 ms: android.os.strictmode.DiskReadViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1556)
        at java.io.UnixFileSystem.getLastModifiedTime(UnixFileSystem.java:289)
        at java.io.File.lastModified(File.java:939)
        at coil.fetch.FileFetcher.key(FileFetcher.kt:14)
        at coil.fetch.FileFetcher.key(FileFetcher.kt:12)
        at coil.RealImageLoader.computeCacheKey(RealImageLoader.kt:276)
        at coil.RealImageLoader.access$computeCacheKey(RealImageLoader.kt:78)
        at coil.RealImageLoader$execute$2$deferred$1.invokeSuspend(RealImageLoader.kt:202)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
        at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:68)
        at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:464)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:154)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
        at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
        at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
        at coil.RealImageLoader.load(RealImageLoader.kt:137)

Library version 0.7.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikepenzcommented, Sep 30, 2019

Not sure how I missed that one.

Anyways from my perspective you may close this. You might want to note somewhere that people who use the FileLoader will face the IO on main thread, and that they can use the key() method to work around this problem

0reactions
colinrtwhitecommented, Oct 1, 2019

Sounds good, I’ll add a note to FileFetcher.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Threading Model - WPF .NET Framework - Microsoft Learn
When the Dispatcher in the UI thread has time, it executes the scheduled call to UpdateUserInterface . This method stops the clock animation...
Read more >
The .join() method block UI thread even when called on a new ...
I have an issue getting the result asynchronously, variable1 keeps blocking the UI thread. To my understanding, .join() waits for the result ...
Read more >
Main thread is blocked with __psynch_mutexwait
Anyway to tell what is blocking the main thread? ... scanAllDoneAction=0x000000010459300c app`partial apply forwarder for closure #1 () -> () in app.
Read more >
Change Log - Coil
Fetcher.key has been replaced with a new Keyer interface. Keyer creates the cache key ... Fix HttpFetcher blocking forever if called from the...
Read more >
Multi-threading in .NET: Introduction and suggestions
Threading ; public class Test { static void Main() { ThreadStart job = new ... These allow you to specify blocks of code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found