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

Fix the SIGQUIT handling system to deal with multiple ANRs properly. #1235

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## TBD

### Bug fixes

* Fix bug that terminated the app when multiple ANRs occur
[#1235](https://github.com/bugsnag/bugsnag-android/pull/1235)

## 5.9.1 (2021-04-22)

### Bug fixes
Expand Down
28 changes: 14 additions & 14 deletions bugsnag-plugin-android-anr/src/main/jni/anr_google.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@
//
// - Register a SIGQUIT handler via sigaction()
//
// - Our handler callback blocks SIGQUIT (allowing the Google handler to work
// again) and sets a flag like "should_report_anr"
//
// - We have another thread waiting on the "should_report_anr" flag, which then
// calls bsg_google_anr_call() after a short delay to raise a SIGQUIT on
// Google's handler thread. Re-raising the signal on the signal handler
// thread won't work because the signaling system in the OS won't finish
// updating the new blocking state until the current signal handler returns.
//
// - Do our handler stuff, delay a short while (like 2 seconds) for Google's
// handlers to finish, then exit our watchdog thread. It's important that
// our watchdog thread stops before the runtime's timeout (currently 20
// seconds), or else we'll be force-killed, which breaks Google reporting
// and the ANR popup in some cases.
// - When our SIGQUIT handler triggers, we block SIGQUIT (so that the Google
// handler can run), then trigger another "worker" thread we have waiting
// to do the actual work, then return. The context switch to the "worker"
// thread debounces the signaling mechanism so that we can trigger the Google
// ANR thread safely. Our SIGQUIT handler MUST NOT run for more than 20
// seconds or else we'll be force-killed, which breaks Google reporting and
// the ANR popup in some cases.
//
// - Our ANR "worker" thread waits for our trigger, calls bsg_google_anr_call()
// to raise a SIGQUIT on Google's handler thread, and then does any extra
// processing we want to happen (this thread doesn't require async-safety).
//
// - When everything is done, we unblock SIGQUIT again so that our handler will
// trigger on the next ANR, and then put the "worker" thread back to sleep.
//
//
// Functionality in this file:
Expand Down
Loading