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

Fatal Exception: java.lang.IllegalStateException: Cannot recycle a resource while it is still acquired #4507

Open
ayyaztalat opened this issue Feb 23, 2021 · 9 comments

Comments

@ayyaztalat
Copy link

I am currently using Glide version : 4.11.0
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

Cannot recycle a resource while it is still acquired
com.bumptech.glide.load.engine.EngineResource.recycle (EngineResource.java:68)
com.bumptech.glide.load.engine.ResourceRecycler$ResourceRecyclerCallback.handleMessage (ResourceRecycler.java:37)
android.os.Handler.dispatchMessage (Handler.java:103)
android.os.Looper.loop (Looper.java:227)
android.app.ActivityThread.main (ActivityThread.java:7822)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1026)

@mkocus
Copy link

mkocus commented Nov 2, 2021

We've got exactly the same issue.
It seems that the glide crashes randomly on production - this issue cannot be replicated locally.

Full stack log:

Fatal Exception: java.lang.IllegalStateException: Cannot recycle a resource while it is still acquired
       at com.bumptech.glide.load.engine.EngineResource.recycle(EngineResource.java:68)
       at com.bumptech.glide.load.engine.ResourceRecycler$ResourceRecyclerCallback.handleMessage(ResourceRecycler.java:37)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6680)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Environment:

  • Android 9
  • Glide 4.12.0

Do you have any ideas how to debug this issue?

@ayyaztalat
Copy link
Author

ayyaztalat commented Nov 2, 2021 via email

@mkocus
Copy link

mkocus commented Nov 2, 2021

Well, we are using glide a lot and cannot locate where precisely this crash happen :/
The steps that you are proposing are totally destructive - clearing glide cache all the time basically kills the performance and is a no-go for us.

@ayyaztalat
Copy link
Author

ayyaztalat commented Nov 2, 2021 via email

@mkocus
Copy link

mkocus commented Nov 2, 2021

Of course, but this is what I have in mind - we just don't want to clear glide cache.

@ayyaztalat
Copy link
Author

ayyaztalat commented Nov 2, 2021 via email

@mkocus
Copy link

mkocus commented Mar 28, 2022

We still didn't managed to fix this issue.
Do you have a knowledge when the glide tries to recycle resource? The stacktrace only shows that this is an async code which receives message to recycle resource - but who sent it and why?

@TWiStErRob TWiStErRob changed the title Fatal Exception: java.lang.IllegalStateException Fatal Exception: java.lang.IllegalStateException: Cannot recycle a resource while it is still acquired Oct 12, 2023
@TWiStErRob
Copy link
Collaborator

I think with a modification shown in #5310, it would be possible to diagnose this further. But I think that PR is not production ready to be merged to Glide.

If you want to investigate this further, one thing I could recommend is hacking the Glide Engine to use this recycler in the PR to be able to see where the recycle is being called from, which might reveal further leads to fix this. To do this, one would need the following setup:

// put this in a LibraryGlideModule:
val engine = Glide::class.java.getDeclaredField("engine").apply { isAccessible = true }.get(glide) as Engine
val modifiedRecycler = InstanceOfResourceRecyclerFromPR()
Engine::class.java.getDeclaredField("resourceRecycler").apply { isAccessible = true }.set(engine, modifiedRecycler)
// If there's ProGuard/R8 add keep rules for the accessed fields.

Note: if we have a repro, things would change a lot, but from what I see in these two issues, there's inconclusive evidence. Out of curiosity how many crashes of this are there in the wild?

cc @lyjSmile @hpdx @ayyaztalat @mkocus

@EzequielAdrianM
Copy link

Galaxy A20 Android 11
The crash doesn't point to any specific line of code in the application.

Fatal Exception: java.lang.IllegalStateException: Cannot recycle a resource while it is still acquired
       at com.bumptech.glide.load.engine.EngineResource.recycle(EngineResource.java:68)
       at com.bumptech.glide.load.engine.ResourceRecycler$ResourceRecyclerCallback.handleMessage(ResourceRecycler.java:37)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8645)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

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