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

[PLAT-6163] Fix recrash deadlocks #1252

Merged
merged 4 commits into from
Dec 9, 2021
Merged

Conversation

nickdowell
Copy link
Contributor

@nickdowell nickdowell commented Dec 8, 2021

Goal

Fix deadlocks that could occur if the crash handling code (or the app's onCrashHandler callback) crashes.

Changeset

  • Fixes a deadlock caused by the Mach exception handling threads being suspended due to context->reservedThreads being clobbered in bsg_kscrashsentry_clearContext().
  • Fixes a deadlock due to thread_terminate being called on original crashing thread when handling a nested Mach exception.
  • Ensures that bsg_kscrashsentry_beginHandlingCrash() is called when an unhandled NSException is detected, so that crashes during crash handling can be identified.

There remains a deadlock on macOS 10.14 and earlier if a signal handler crashes. This appears to be a bug in the OS and not something we can work around.

Sample code
#include <signal.h>
#include <stdlib.h>

static void signal_handler(int signum) {
  // Crashing the signal handler in this way will deadlock on macOS <= 10.14
  // on more recent versions of macOS the process will terminate as expected.
  static volatile int *ptr;
  *ptr = 42;
}

int main(int argc, const char * argv[]) {
  signal(SIGABRT, signal_handler);
  abort();
  return 0;
}

Testing

E2E tests have been set up on a separate branch (will be included in a future PR) and passed on CI: https://buildkite.com/bugsnag/bugsnag-cocoa/builds/4195

@nickdowell nickdowell changed the base branch from master to next December 8, 2021 14:33
@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Infer: No issues found 🎉

OCLint: No issues found 🎉

Bugsnag.framework binary size did not change - 1,253,256 bytes

Generated by 🚫 Danger

@nickdowell nickdowell merged commit e89664e into next Dec 9, 2021
@nickdowell nickdowell deleted the nickdowell/fix-recrash-deadlocks branch December 9, 2021 08:09
@nickdowell nickdowell mentioned this pull request Jan 5, 2022
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