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

Conversation

kstenerud
Copy link
Contributor

Goal

Bugsnag wasn't handling things properly when multiple ANRs occur. This PR fixes it.

Design

The old handler would run once and exit, replacing the SIGQUIT handler with what was there before. This is the correct design for traditional signal handlers, but breaks in a Google ANR handler environment. Subsequent ANRs would trigger the default POSIX signal handler, which terminates the app.

Instead, we need the handler thread to run in a loop, blocking and unblocking SIGQUIT as necessary in order to coordinate with the Google ANR handler, and never setting the system to use the default handler.

Testing

These changes must be tested manually, which will happen on multiple devices at the beginning of the week. Do not merge until these tests are complete!

Copy link
Contributor

@tomlongridge tomlongridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a changelog entry.

Other nits mentioned below, but I'll leave the main functionality review for @fractalwrench as I'm not close-enough to the detail.

struct sigaction handler;
sigemptyset(&handler.sa_mask);
handler.sa_sigaction = handle_sigquit;
handler.sa_flags = SA_SIGINFO;
if (sigaction(SIGQUIT, &handler, &original_sigquit_handler) != 0) {
if (sigaction(SIGQUIT, &handler, NULL) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fact that we're not restoring the original handler here should be supported by some comments to justify this for future readers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this work for environments such as Unity where ANR detection needs to be dynamically enabled/disabled via the Bugsnag.SetAutoNotify() api?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When bugsnag is disabled, SIGQUIT is blocked and the default handler is never called. When bugsnag is enabled, our handler gets called. Either way, the default SIGQUIT handler never gets called in an Android app (and must never be called because it would terminate the app).

bugsnag-plugin-android-anr/src/main/jni/anr_handler.c Outdated Show resolved Hide resolved
bugsnag-plugin-android-anr/src/main/jni/anr_google.c Outdated Show resolved Hide resolved
@kstenerud kstenerud force-pushed the 6477-fix-for-multiple-anrs branch 2 times, most recently from 80f44ec to cb0768b Compare May 7, 2021 13:29
@kstenerud kstenerud force-pushed the 6477-fix-for-multiple-anrs branch from cb0768b to 4c13f8d Compare May 7, 2021 13:32
Copy link
Contributor

@fractalwrench fractalwrench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with these changes as long as they're tested out on a wide variety of devices. Added a question about Unity support inline.

struct sigaction handler;
sigemptyset(&handler.sa_mask);
handler.sa_sigaction = handle_sigquit;
handler.sa_flags = SA_SIGINFO;
if (sigaction(SIGQUIT, &handler, &original_sigquit_handler) != 0) {
if (sigaction(SIGQUIT, &handler, NULL) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this work for environments such as Unity where ANR detection needs to be dynamically enabled/disabled via the Bugsnag.SetAutoNotify() api?

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.

3 participants