Skip to content

fix: app hang detection on android when uaal - #2920

Merged
bitsandfoxes merged 1 commit into
mainfrom
fix/android-main-process-app-hang
Oct 30, 2026
Merged

bitsandfoxes merged 1 commit into
mainfrom
fix/android-main-process-app-hang

Conversation

@bitsandfoxes

Copy link
Copy Markdown
Contributor

Follow-up to #2895. On Android with Unity as a Library, game hangs were never detected when the game attaches to the app's sentry-android (Unity in the app's main process).

sentry-native's app hang detection only watches a thread that sends heartbeats (sentry_app_hang_heartbeat), and it does nothing until one arrives. sentry-android only passes enableNdkAppHangTracking on to native init and never sends heartbeats itself; downstream SDKs are expected to. When attached, the game skipped its heartbeat, so detection was never armed. The app's JVM ANR detection watches the UI thread, not the game thread.

Now, when attached, the game sends the heartbeat if the app's SDK has isEnableNdk() and isEnableNdkAppHangTracking() on. The app's options decide, as for all native options when attached. Unity's EnableAppHangTracking/AppHangTimeout can't apply there, because the app's sentry_init already set up the watchdog. As before, the C# watchdog is removed only when the heartbeat runs.

Unload/reload false app hang (both Android UaaL layouts)

Testing this turned up a false app hang after the app unloads and reloads the game, also in the :Unity layout. On reload Unity restarts Time.frameCount and Time.realtimeSinceStartup. The heartbeat coroutine was suspended across the unload, so it only resumed once the new clock caught up with the old one: on the device, ~27 s later, about as long as the game had run. Meanwhile the beat on resume had already re-armed detection, so a hang was reported ~5 s after the reload. The heartbeat coroutine now restarts on resume.

Verified on a Pixel 6 (Android 16, local UaaL host on sentry-android 8.59.0 with setEnableNdkAppHangTracking(true))

Main process (attached) :Unity
10 s main-thread hang 1 AppHang 1 AppHang
4 show/back cycles none none
app unloads the game, reload none none
Application.Unload(), reload, then a hang 1 AppHang 1 AppHang

Before this change, a 10 s hang in the main-process layout produced no event.

#skip-changelog: #2895 isn't released yet.

🤖 Generated with Claude Code

@bitsandfoxes
bitsandfoxes requested review from a team, jpnurmi, limbonaut and tustanivsky October 30, 2026 09:54
@bitsandfoxes
bitsandfoxes merged commit 91fc254 into main Oct 30, 2026
131 of 132 checks passed
@bitsandfoxes
bitsandfoxes deleted the fix/android-main-process-app-hang branch October 30, 2026 11:11
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

Successfully merging this pull request may close these issues.

2 participants