fix(ios): Prevent managed exceptions from leaking as NSExceptions - #5525
Open
jpnurmi wants to merge 2 commits into
Open
fix(ios): Prevent managed exceptions from leaking as NSExceptions#5525jpnurmi wants to merge 2 commits into
jpnurmi wants to merge 2 commits into
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After Sentry .NET captures an unhandled exception in
Runtime.MarshalManagedException, the defaultThrowObjectiveCExceptionmode throws anNSException.The existing managed-crash test throws through
NSAsyncActionDispatcher, where .NET’sUIApplicationMainwrapper catches theNSExceptionbefore Sentry Cocoa observes it. The new test throws fromUIApplicationDelegate.OnActivated, reproducing the path where theNSExceptionreaches Sentry Cocoa’s uncaught-exception handler and creates a duplicate event.This changes the per-event mode to
Abortafter capture, preventing theNSException. The existing one-shotSIGABRTsuppression ignores the runtime’s resulting unconditionalabort().Close: #5493