feat(android): allow NDK preload for .NET/CoreCLR#1613
Conversation
|
8fb200b to
593a225
Compare
Add sentry__backend_preload() for installing signal handlers before sentry_init(). For the inproc backend on Unix/Android, this allows establishing the correct signal handler chain order when another runtime (e.g. Mono/.NET) installs its own handlers later. - Backend dispatch: sentry__backend_preload() (no-op for non-inproc) - Extracted install_signal_handlers() with idempotency flag - Preload fallthrough: if handler thread not ready, invoke previous handler - NDK: SentryNdkPreloadProvider ContentProvider with high initOrder for early signal handler installation before Mono runtime - NDK: Java/JNI preload() method on SentryNdk Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Mono: chain-at-start (preload requires dotnet/runtime#125835) - CoreCLR: preload (chain-at-start blocked by libsigchain) - Auto-build the NDK AAR for preload tests
…preload When preloaded, skip handler teardown on sentry_close() so the runtime's handler chain remains intact for subsequent sentry_init(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
593a225 to
750c178
Compare
Fixes unused variable warning on Windows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevents infinite loop when the previous handler is SIG_DFL: without resetting, raise() re-enters sentry's handler due to SA_NODEFER. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The refactoring into install_signal_handlers() lost the error return. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
In practice, the process is about to die (SIG_DFL on a fatal signal), so this state is never observed. But clear it anyway for consistency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
supervacuus
left a comment
There was a problem hiding this comment.
This looks good to me in concept and essence, but I would add a few more clarifications. I know it is entirely clear to you now, but since there are a lot of implicit assumptions encoded, we can prose this up a bit.
Please also add a note in sentry.h for sentry_close() highlighting the intentional life-cycle change. Even if we do not consider this to be a public API, the header is the right place for other maintainers. Something like:
The Android preload mode of
inprocis a special case: a lightweight signal-chain placeholder may remain installed acrosssentry_close()to preserve ordering relative to the managed runtime until a later re-init.
Appended to the paragraph that remarks on the crash-handler life-cycle.
Co-authored-by: Mischan Toosarani-Hausberger <mischan@abovevacant.com>
Co-authored-by: Mischan Toosarani-Hausberger <mischan@abovevacant.com>
Co-authored-by: Mischan Toosarani-Hausberger <mischan@abovevacant.com>
|
Big thanks for the suggestions! And sorry to make you spend so much time writing docs and comments for this change! 😵💫 |
You're welcome!
Not at all, I actually think that me writing the code-level docs as part of the review is the right choice here. |

.NET 10.0 added support for CoreCLR on Android (experimental). Unlike with the Mono runtime, where we're stuck with
CHAIN_AT_START(dotnet/runtime#125835), with CoreCLR we can already reorder the signal handlers to the preferred order:This gives the .NET runtime a chance to process managed .NET exceptions without Sentry Native stepping on its toes. This is much safer than
CHAIN_AT_START, and will be automatically enabled (io.sentry.ndk.preload=true) by Sentry.NET when targeting Android .NET 10.0 or later with CoreCLR.Changes
Add
sentry__backend_preload()for installing signal handlers beforesentry_init(). For the inproc backend on Unix/Android, this allows establishing the correct signal handler chain order when another runtime (e.g. Mono/.NET) installs its own handlers later.sentry__backend_preload()(no-op for non-inproc)install_signal_handlers()with idempotency flagSentryNdkPreloadProvidercontent provider with high init order for early signal handler installation before the CoreCLR runtimepreload()method on SentryNdkSee also