Skip to content

Managed NullReferenceException causes EXC_BAD_ACCESS and SIGSEGV errors on iOS and Android  #3902

Closed
2 of 2 issues completed
@jamescrosswell

Description

@jamescrosswell

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

Sub-issues

Metadata

Metadata

Labels

BugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions