Skip to content

fix(ios): Prevent managed exceptions from leaking as NSExceptions - #5525

Open
jpnurmi wants to merge 2 commits into
mainfrom
jpnurmi/fix/nsexception
Open

fix(ios): Prevent managed exceptions from leaking as NSExceptions#5525
jpnurmi wants to merge 2 commits into
mainfrom
jpnurmi/fix/nsexception

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

After Sentry .NET captures an unhandled exception in Runtime.MarshalManagedException, the default ThrowObjectiveCException mode throws an NSException.

The existing managed-crash test throws through NSAsyncActionDispatcher, where .NET’s UIApplicationMain wrapper catches the NSException before Sentry Cocoa observes it. The new test throws from UIApplicationDelegate.OnActivated, reproducing the path where the NSException reaches Sentry Cocoa’s uncaught-exception handler and creates a duplicate event.

This changes the per-event mode to Abort after capture, preventing the NSException. The existing one-shot SIGABRT suppression ignores the runtime’s resulting unconditional abort().

Close: #5493

Managed exceptions escaping iOS callbacks can be marshaled into NSExceptions
and captured a second time by Sentry Cocoa. Exercise this boundary through
AppDelegate.OnActivated and assert that only the managed event is emitted.
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Aug 31, 2026
Comment thread integration-test/ios.Tests.ps1
Comment thread integration-test/net9-maui/App.xaml.cs
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.75%. Comparing base (fd638f0) to head (b1e042b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5525   +/-   ##
=======================================
  Coverage   74.75%   74.75%           
=======================================
  Files         515      515           
  Lines       18884    18884           
  Branches     3688     3688           
=======================================
  Hits        14116    14116           
  Misses       3884     3884           
  Partials      884      884           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Managed exceptions escaping native-to-managed callbacks trigger
Runtime.MarshalManagedException. Its default behavior converts the exception
into an NSException, allowing Sentry Cocoa to capture the same failure again.

After capturing the callback exception, switch the per-event mode to Abort and
rely on the existing one-shot SIGABRT suppression for the resulting runtime
abort.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS 26.3 and up produces duplicate crash reports

1 participant