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

Managed NullReferenceException causes SIGSEGV errors on iOS and Android #3902

Open
jamescrosswell opened this issue Jan 16, 2025 · 0 comments
Labels
Bug Something isn't working

Comments

@jamescrosswell
Copy link
Collaborator

jamescrosswell commented Jan 16, 2025

Problem

When the Sentry Native SDK is used in apps that are AOT compiled (for example when publishing Android or iOS apps in release mode), SIGSEGV reports are captured by the NDK for managed NullReferenceException exceptions, even when the managed code in question catches and handles such exceptions.

Steps to reproduce

  • Create a MAUI app
  • Add a button with some code that will generate a NullReferenceException in the event handler... e.g.:
            string s = null;
          _logger.LogInformation("The length of the string is {StringLength}", s!.Length);
    
  • Run the application in Release mode on a Simulator

Expected Result

A managed NullReferenceException should be captured by the .NET SDK

Actual Result

In addition to a NullReferenceException being captured by the .NET SDK, SIGSEGV signal error is captured by the NDK (on Android) or the CocoaSDK (on iOS).

Analysis

Full analysis from @supervacuus here:

On the basis of the analysis above, we attempted to invert the order in which the Native and Managed signal handlers get run in this PR:

However this led to users' applications crashing (rather than just reporting erroneous SIGSEGV errors). So this change was reverted in:

Gist

📄 NullReference SIGSEGV Exception.pdf

Current State

We don't have the required resources available on the Native team to solve this end-to-end at the moment, so coming back to #3861 (comment), we need to recommend deactivating the native crash reporters on Android and iOS for MAUI for the time being to mitigate the issue of duplicate reports.

However we're in the process of getting more resources on the downstream team(s) which means we'll hopefully be able to tackle the root cause some time in the next few months.

Originally posted by @kahest in #3861

Workaround (short term)

In the short term, we will try to disable Native Crash reporting of SIGSEGV exceptions.

Solution (long term)

Eventually, we need to work out how to make the dotnet and native SDKs play nicely together, so that native exceptions are captured, but only when they have not already been translated to and captured as managed exceptions.

Related issues

Android

iOS

@jamescrosswell jamescrosswell added the Bug Something isn't working label Jan 16, 2025
@jamescrosswell jamescrosswell changed the title Disable NDK to prevent erroneous SIGSEGV reports Managed NullReferenceException causes SIGSEGV errors on iOS and Android Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant