fix: prevent redundant native exceptions on iOS#5126
fix: prevent redundant native exceptions on iOS#5126jpnurmi wants to merge 1 commit intojpnurmi/build/cocoa-submodulefrom
Conversation
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Fixes 🐛
Dependencies ⬆️Deps
🤖 This preview updates automatically when you update the PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## jpnurmi/build/cocoa-submodule #5126 +/- ##
==============================================================
Coverage 73.98% 73.98%
==============================================================
Files 499 499
Lines 18067 18067
Branches 3520 3520
==============================================================
Hits 13366 13366
Misses 3839 3839
Partials 862 862 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@jamescrosswell @Flash0ver Is turning sentry-cocoa into a submodule and building it on the fly a deal-breaker? Maybe we could cache sentry-cocoa builds in the CI similarly to sentry-native? I hate that it slows down local builds, though... 😭 |
c4f6ee3 to
0fdf17d
Compare
|
My biggest concern was the impact of replacing the officially released and signed bundle with an unsigned self-built bundle. TL;DR: DetailsSurprising finding about Sentry's release signingThe $ codesign -dv --verbose=4 Sentry-9.7.0.xcframework
Authority=Apple Distribution: GetSentry LLC (97JCY7859U)
Authority=Apple Worldwide Developer Relations Certification Authority
Authority=Apple Root CA
TeamIdentifier=97JCY7859U
Sealed Resources version=2 rules=10 files=789
$ codesign -dv --verbose=4 Sentry-9.7.0.xcframework/ios-arm64/Sentry.framework
.../ios-arm64/Sentry.framework: code object is not signed at allThe dotnet-ios re-signs with
|
Allows building sentry-cocoa with `SENTRY_CRASH_MANAGED_RUNTIME` for eliminating duplicate native exceptions on iOS. See also: - getsentry/sentry-cocoa#6193 - #5126
42ca1ff to
1b3eee3
Compare
|
Problem: On iOS, we needed Sentry Cocoa to install signal handlers before the .NET runtime. We couldn't call any API from .NET because it was too late. The .NET runtime was already up and running and had installed its signal handlers. Fix: The solution was to pre-install signal handlers very early at Sentry Cocoa library load time. No full SDK init, just pre-install the signal handlers, and make them operate in a special passthrough mode until the SDK is fully initialized. The problem was that we did not want this to affect normal SDK users, so I guarded the behavior behind a compile-time flag to make it an easier sell. Deploy: To be able to ship Sentry.NET + Sentry Cocoa with
Note: It's also a viable option to go with a submodule for the short term, and switch back to prebuilt releases as soon as an official Managed variant is available. |
I think I'm not understanding the sequence of events that leads to sentry-cocoa being loaded. I thought no code from sentry-cocoa would be executed (in the context of a c# application at least) until we call e.g. we could do this when initialising the .NET SDK (before calling And then code like this could check for the existence of that environment variable rather than using a compile time pragma. But all of that is probably unnecessary - we could just pass something in via the options if the load sequence was as I (presumably falsely) assumed above. How does the signal handler registration happen for sentry-cocoa when it's being used from a hybrid SDK then? How does your code pre register the signal handlers before we call |
The .NET/Mono runtime is initialized from the native Since Sentry's signal handlers must be in place before the .NET runtime initializes, calling any API, specifying environment variables, or anything alike from within .NET itself is too late, because the .NET runtime is already running. We use |
Allows building sentry-cocoa with `SENTRY_CRASH_MANAGED_RUNTIME` for eliminating duplicate native exceptions on iOS. See also: - getsentry/sentry-cocoa#6193 - #5126
4071bee to
acf4165
Compare
1b3eee3 to
dc98de1
Compare
I see... dang. In that case, we don't have too many choices. We either build sentry-cocoa ourselves or wait until a special build for .NET can be made available. How much time are we talking about adding (presumably at least every time we start a new branch locally - at least in my case - I'm using git work trees)? |
|
Depends on network vs. CPU speed, but building Prebuilt release (current
|
|
Doesn't look like there's any way around it. I guess on the up side, we no longer have to download the binaries... so there's that. 🌤️ |
|
Hmm, right... my comparison was actually not quite fair. The overhead of downloading moves to the init phase of your worktree, because you need to clone the sentry-cocoa submodule too... Gladly, sentry-cocoa initializes faster than sentry-native and doesn't have any submodules of its own, but it still easily adds an extra 15-30s per worktree init. |
- Build sentry-cocoa with SENTRY_CRASH_MANAGED_RUNTIME to preload signal handlers and exclude EXC_BAD_ACCESS/EXC_ARITHMETIC from Mach monitoring - Call PrivateSentrySDKOnly.IgnoreNextSignal(SIGABRT) from MarshalManagedException to prevent duplicate native crash events - Update iOS integration tests to expect no duplicate events (#3954) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dc98de1 to
0febb68
Compare
Note
Depends on sentry-cocoa 9.10.0 + modules/sentry-cocoa submodule:
Fixes duplicate native exceptions (#3954) on iOS by reordering signal handlers to let .NET/Mono handle managed exceptions first, and then chain real native exceptions to Sentry.
Before:
After:
Good news: the re-ordered signal handlers are working as expected.
Bad news: The early signal handler installation in getsentry/sentry-cocoa#6193 is guarded behind a
SENTRY_CRASH_MANAGED_RUNTIMEcompile-time flag to avoid affecting normal Cocoa SDK users. iOS integration tests were happily passing while developing with a localmodules/sentry-cocoaclone, but I do realize now that this cannot work with the pre-builtSentry.xcframeworkrelease bundles built withoutSENTRY_CRASH_MANAGED_RUNTIME... 🤦