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 uninstalling signal handlers #976

Merged
merged 1 commit into from
Feb 5, 2021

Conversation

blaztinn
Copy link

@blaztinn blaztinn commented Jan 19, 2021

Goal

Allow other signal handlers besides bugsnag's.

Design

When trying bugsnag I noticed that my custom signal handlers weren't
triggered. After debugging I found out that bugsnag catches a mach
exception and uninstalls both mach and signal handlers
(bsg_kscrashsentry_uninstall(BSG_KSCrashTypeAsyncSafe)).

The problem is that when uninstalling bugsnag's signal handler it resets to the
previously installed handler, this results in removing all the signal handlers
installed after bugsnag's (which was the case for my signal handler).

To solve this, disable signal handlers instead of uninstalling them. Do it this
way because:

  1. Signal handlers installed after bugsnag's can take bugsnag's signal handling
    function address and call it. In this case the function must always work and
    chain calls forward.
  2. If multiple signal handlers for same signal are installed after bugsnag's we
    can't remove bugsnag's without removing all but the last installed one.

Because we don't uninstall bugsnag's signal handlers we now always directly
call previously installed signal handlers inside the bugsnag's signal handler.

Changeset

Changed that signal handler is always installed once installed. On uninstall
it gets disabled, where it doesn't handle the crash but only forwards the call
to previous signal handlers.

Testing

After the change both bugsnag and my custom handler handled the crash.

Test-Bugsnag-iOS-2021.01.19_08-19-20-+0100.xcresult.zip

@xljones xljones added backlog We hope to fix this feature/bug in the future bug Confirmed bug labels Jan 19, 2021
@xljones
Copy link
Contributor

xljones commented Jan 19, 2021

Thanks for raising this PR, we like the idea here. We'll review this as priorities allow, and we'll keep you updated on this thread.

@nickdowell nickdowell changed the base branch from master to next January 19, 2021 09:02
When uninstalling signal handlers disable them instead of uninstalling.
Do it this way because:

1. Signal handlers installed after ours can take our signal handling
function address and chain to it. In this case the function must always
work.
2. If multiple signal handlers for same signal are installed after ours
we can't remove ours without removing all but the last installed one.

Because we don't uninstall our signal handlers we now directly call
previously installed signal handlers.
@bugsnagbot bugsnagbot added scheduled Work is starting on this feature/bug and removed backlog We hope to fix this feature/bug in the future labels Feb 4, 2021
@nickdowell nickdowell merged commit b39ca2e into bugsnag:next Feb 5, 2021
@yousif-bugsnag
Copy link
Contributor

Fixed in v6.6.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug released This feature/bug fix has been released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants