Skip to content

Commit

Permalink
Fix the SIGQUIT handling system to deal with multiple ANRs properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
kstenerud committed May 7, 2021
1 parent 057ea5d commit cb0768b
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 128 deletions.
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 our watchdog
// 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

0 comments on commit cb0768b

Please sign in to comment.