bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.47k stars 6.11k forks source link

Glide threads are blocked #4609

Closed pawan52tiwari closed 2 years ago

pawan52tiwari commented 2 years ago

I am using Glide in android tv app. We are using react native which is using the fast image that also usage the Glide. And android native is also using the Glide. But we are seeing lot of ANRs In ANR dump mostly Glide threads are blocked.

Example


"glide-source-thread-3" prio=5 tid=130 Blocked
  | group="main" sCount=1 dsCount=0 obj=0x23abdfa0 self=0xb937b5b0
  | sysTid=10376 nice=9 cgrp=default sched=0/0 handle=0xb942ceb8
  | state=S schedstat=( 519932382 663407692 1058 ) utm=37 stm=14 core=3 HZ=100
  | stack=0x87369000-0x8736b000 stackSize=1036KB
  | held mutexes=
  at com.bumptech.glide.disklrucache.DiskLruCache.get(DiskLruCache.java:-1)
  - waiting to lock <0x1ab91180> (a com.bumptech.glide.disklrucache.DiskLruCache) held by thread 118
  at com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper.get(DiskLruCacheWrapper.java:94)
  at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:57)
  at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:50)
  at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
  at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
  at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:818)
  at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)

"glide-source-thread-2" prio=5 tid=118 Native
  | group="main" sCount=1 dsCount=0 obj=0x23a0a460 self=0xb945d9d8
  | sysTid=10342 nice=9 cgrp=default sched=0/0 handle=0xb942ea48
  | state=S schedstat=( 874300909 654029153 1313 ) utm=60 stm=27 core=0 HZ=100
  | stack=0x882db000-0x882dd000 stackSize=1036KB
  | held mutexes=
  kernel: (couldn't read /proc/self/task/10342/stack)
  native: #00 pc 00012ac0  /system/lib/libc.so (syscall+28)
  native: #01 pc 000a98af  /system/lib/libart.so (_ZN3art17ConditionVariable4WaitEPNS_6ThreadE+82)
  native: #02 pc 001ce137  /system/lib/libart.so (_ZN3art3JNI24ReleaseByteArrayElementsEP7_JNIEnvP11_jbyteArrayPai+914)
  native: #03 pc 00016bf1  /system/lib/libjavacore.so (???)
  native: #04 pc 0001e98b  /system/lib/libjavacore.so (???)
  native: #05 pc 00021535  /system/lib/libjavacore.so (???)
  native: #06 pc 00284ea3  /system/framework/arm/boot.oat (Java_libcore_io_Posix_writeBytes__Ljava_io_FileDescriptor_2Ljava_lang_Object_2II+142)
  at libcore.io.Posix.writeBytes(Native method)
  at libcore.io.Posix.write(Posix.java:259)
  at libcore.io.BlockGuardOs.write(BlockGuardOs.java:313)
  at libcore.io.IoBridge.write(IoBridge.java:497)
  at java.io.FileOutputStream.write(FileOutputStream.java:204)
  at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
  - locked <@addr=0x23de3120> (a java.io.FileOutputStream)
  at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
  at java.io.BufferedWriter.flush(BufferedWriter.java:124)
  - locked <@addr=0x23de3100> (a java.io.OutputStreamWriter)
  at com.bumptech.glide.disklrucache.DiskLruCache.flushWriter(DiskLruCache.java:704)
  at com.bumptech.glide.disklrucache.DiskLruCache.completeEdit(DiskLruCache.java:563)
  - locked <0x1ab91180> (a com.bumptech.glide.disklrucache.DiskLruCache)
  at com.bumptech.glide.disklrucache.DiskLruCache.access$2100(DiskLruCache.java:90)
  at com.bumptech.glide.disklrucache.DiskLruCache$Editor.commit(DiskLruCache.java:835)
  at com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper.put(DiskLruCacheWrapper.java:132)
  at com.bumptech.glide.load.engine.SourceGenerator.cacheData(SourceGenerator.java:108)
  at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:47)
  at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
  at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
  at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:818)
  at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)

Is something wrong with the way we could be using the Glide between React native and Native.

pawan52tiwari commented 2 years ago

there are lot ANR crash happening due to this

DALVIK THREADS (199):
"main" prio=5 tid=1 Suspended
  | group="main" sCount=1 dsCount=0 obj=0x7444d000 self=0xb6ff6e98
  | sysTid=14608 nice=-4 cgrp=default sched=0/0 handle=0xb6fc7000
  | state=S schedstat=( 359300372112 84333204824 721701 ) utm=27185 stm=8745 core=2 HZ=100
  | stack=0xbe1db000-0xbe1dd000 stackSize=8MB
  | held mutexes=
  at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:178)
  at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:779)
  at android.view.Choreographer.doCallbacks(Choreographer.java:592)
  at android.view.Choreographer.doFrame(Choreographer.java:559)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:767)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5604)
  at java.lang.reflect.Method.invoke!(Native method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

"glide-disk-cache-thread-0" prio=5 tid=64 Blocked
  | group="main" sCount=1 dsCount=0 obj=0x132d4940 self=0xb735a078
  | sysTid=14912 nice=9 cgrp=default sched=0/0 handle=0xb7693160
  | state=S schedstat=( 4972521855 20263114853 10607 ) utm=385 stm=112 core=3 HZ=100
  | stack=0x8b850000-0x8b852000 stackSize=1036KB
  | held mutexes=
  at com.bumptech.glide.disklrucache.DiskLruCache.get(DiskLruCache.java:-1)
  - waiting to lock <0x260b05cb> (a com.bumptech.glide.disklrucache.DiskLruCache) held by thread 95
  at com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper.get(DiskLruCacheWrapper.java:94)
  at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:85)
  at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
  at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:276)
  at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:818)
  at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)

"glide-source-thread-0" prio=5 tid=95 Native
  | group="main" sCount=1 dsCount=0 obj=0x13c5a460 self=0xb76e6c38
  | sysTid=14943 nice=9 cgrp=default sched=0/0 handle=0xb76e68a0
  | state=S schedstat=( 1612669901 5220033107 3533 ) utm=128 stm=33 core=0 HZ=100
  | stack=0x8afaf000-0x8afb1000 stackSize=1036KB
  | held mutexes=
  kernel: (couldn't read /proc/self/task/14943/stack)
  native: #00 pc 00012ac0  /system/lib/libc.so (syscall+28)
  native: #01 pc 000a98af  /system/lib/libart.so (_ZN3art17ConditionVariable4WaitEPNS_6ThreadE+82)
  native: #02 pc 001c1529  /system/lib/libart.so (_ZN3art3JNI17GetStringUTFCharsEP7_JNIEnvP8_jstringPh+672)
  native: #03 pc 000139eb  /system/lib/libjavacore.so (???)
  native: #04 pc 000211db  /system/lib/libjavacore.so (???)
  native: #05 pc 0009c2a7  /system/framework/arm/boot.oat (Java_libcore_io_Posix_access__Ljava_lang_String_2I+106)
  at libcore.io.Posix.access(Native method)
  at libcore.io.BlockGuardOs.access(BlockGuardOs.java:68)
  at java.io.File.doAccess(File.java:283)
  at java.io.File.exists(File.java:363)
  at com.bumptech.glide.disklrucache.DiskLruCache$Editor.getFile(DiskLruCache.java:807)
  - locked <0x260b05cb> (a com.bumptech.glide.disklrucache.DiskLruCache)
  at com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper.put(DiskLruCacheWrapper.java:130)
  at com.bumptech.glide.load.engine.SourceGenerator.cacheData(SourceGenerator.java:108)
  at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:47)
  at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
  at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
  at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:818)
  at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
sjudd commented 2 years ago

Glide's threads being blocked should never cause an ANR, unless you've deliberately blocked the main thread while waiting for an image load. Glide tries to prevent this via assertions, but it is possible to workaround it. In the above stack traces I don't see the main thread being blocked on Glide. So there's another cause for the ANR.

It does look like Glide's threads are blocked trying to make a system call to access a File. That is normally quite fast, which suggests something wrong with the device or sdcard.