fix: pause app hang detection when going on the background - #1506
fix: pause app hang detection when going on the background#1506bitsandfoxes wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1e1ac54. Configure here.
| { | ||
| AppHangPauseFunc = reinterpret_cast<void (*)()>(dlsym(libsentryHandle, "sentry_app_hang_pause")); | ||
|
|
||
| if (AppHangPauseFunc) | ||
| { | ||
| UE_LOG(LogSentrySdk, Log, TEXT("Resolved sentry_app_hang_pause for NDK app-hang tracking.")); | ||
| } | ||
| } | ||
|
|
||
| dlclose(libsentryHandle); | ||
| } |
There was a problem hiding this comment.
Bug: A data race exists on AppHangHeartbeatFunc and AppHangPauseFunc as they are accessed from multiple threads without atomic or mutex protection, leading to undefined behavior.
Severity: MEDIUM
Suggested Fix
Protect the reads and writes to AppHangHeartbeatFunc and AppHangPauseFunc within ResolveAppHangFunctions(). This can be achieved by using a FCriticalSection to lock around the check and subsequent dlsym calls. Alternatively, convert the function pointers to TAtomic<TFunction<...>> or a similar atomic type.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp#L624-L656
Potential issue: A data race exists on the non-atomic function pointers
`AppHangHeartbeatFunc` and `AppHangPauseFunc`. The function `ResolveAppHangFunctions()`,
which reads and writes these pointers, is called from the game thread via
`PumpAppHangHeartbeat()` and potentially from a different thread via
`PauseAppHangTracking()`. This concurrent access without a mutex or atomic operations is
undefined behavior. The initial check `if (AppHangHeartbeatFunc && AppHangPauseFunc)` is
a racy read. While the practical impact might be limited to redundant `dlsym` calls on
some hardware, a torn pointer read could theoretically lead to a crash when the garbage
pointer is called.
|
Here are several findings about Unreal's app‑lifecycle delegates that are worth considering here:
Given these differences, I'd suggest reshaping the generic‑platform implementation so that downstream plugin extensions can control which delegates they subscribe to and how they map to pause/resume, e.g. a virtual Also, for Xbox and Switch we should probably validate this behavior on actual devkits and see whether hiding/resuming the app actually produces false‑positive hangs since it's something hard to confirm only by looking into engine sources. |
# Conflicts: # CHANGELOG.md
|
Superseded by #1523 |

Relies on getsentry/sentry-native#1928
To prevent false positives like reporting an app hang event because the game went on the background.