-
-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Android: Fix ANRs when shutting down the engine due to the render thread #114207
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
Conversation
37bd9d4 to
0f21699
Compare
|
Is killing a thread not a big deal? I have no issue if Android is fine with you just killing stuff off when necessary. From a rendering perspective, the only potential issue I foresee is that the pipeline cache is saved on exit and killing the thread early may either cause that to be corrupted, or just not happen at all. Which would create a similar issue to #111319 Alternatively, is there a way for us to poll for the completion of tasks at shutdown instead of waiting? That way perhaps the main thread could at least avoid the ANR even if shutdown takes a little bit of time |
platform/android/java/lib/src/main/java/org/godotengine/godot/gl/GLSurfaceView.java
Outdated
Show resolved
Hide resolved
Is the pipeline cache saved as part of
On app exit, the Android runtime makes the app go through the DESTROY state by calling Re (1), for 4.7 I'm exploring having a background service by leveraging |
0f21699 to
e77d70c
Compare
Looks like it, it's triggered here: godot/platform/android/display_server_android.cpp Lines 816 to 818 in 8a6408c
Which gets called from In any case, I think being able to explicitly trigger it is important for solving #111319
Maybe we are getting dead locks on exit?
This makes me think that the root of the issue is a deadlock in Have you been able to reproduce this issue locally at all? |
e77d70c to
6098674
Compare
Yes we are getting dead locks on exit. I haven't been able to reproduce the issue locally, but from the store logs it occurs both on Quest and Android devices across a wide range of devices.
Deadlock in the Other (less common) sources include:
|
akien-mga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit heavy handed to have to force terminate the app within less than a second to avoid Android considering a bit of thread join delay a deadlock... but that's what we have to work with, and I agree a force termination is better than an ANR report.
We should definitely have issues opened for the most common occurrences of this ANR, especially if we're going to stop getting these reports and not know that user logcat's in the wild are spammed with warnings of early termination.
platform/android/java/lib/src/main/java/org/godotengine/godot/Godot.kt
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/main/java/org/godotengine/godot/gl/GLSurfaceView.java
Outdated
Show resolved
Hide resolved
6098674 to
c9fc96f
Compare
The default ANR timeout is 5 seconds and it's triggered when the main UI thread is blocked for that long so it can be either be a deadlock or just an operation taking longer than 5 seconds and blocking the main UI thread. When Also the issue occurs for both
I'll open corresponding issues in the morning. |
c9fc96f to
422cc7b
Compare
platform/android/java/lib/src/main/java/org/godotengine/godot/vulkan/VkThread.kt
Show resolved
Hide resolved
|
Thanks! |
|
Cherry-picked for 4.5.2. |
This addresses the ANRs (Application Not Responding) reports from the Google Play and Horizon stores:
Diving into the report from the Google Play store shows that the ANRs tend to occur on application exit when the main thread is waiting for the render thread to clean up and shutdown the engine.
In certain conditions however, the render thread ends up itself being blocked waiting on internal threads to complete their cleanup. For example, in the logs below, the render thread is blocked by the destruction of the
IPobject which is blocked onresolver->thread.wait_to_finish();.This PR fixes the issue by adding a timeout for how long the main thread should wait for the render thread. On expiry of the timeout, the main thread gives up on waiting on the render thread and force kill the process.