Skip to content

fix(android): support out-of-process crash handling on API 21+ - #6614

Open
jpnurmi wants to merge 14 commits into
mainfrom
jpnurmi/fix/native-android-21
Open

jpnurmi wants to merge 14 commits into
mainfrom
jpnurmi/fix/native-android-21

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ DO NOT MERGE YET (revert 1eca506 after releasing getsentry/sentry-native#2301)

📜 Description

A follow-up to #6347:

  • Drop the API 30 requirement from sentry-android-ndk-outproc.
  • Pass the database directory to SentryNdk.createCrashShm(String), which falls back to a file without memfd_create (Linux < 3.17).
  • Read the process name from /proc/self/cmdline below API 28 to skip SDK init in the crash service process.
  • Start the crash service without blocking SentryAndroid.init() for up to 10 s.

💡 Motivation and Context

Before, outproc required API 30+ while inproc supports API 21+. Now, both support API 21+.

💚 How did you test it?

The Android E2E tests in getsentry/sentry-native#2301 build this branch and run on API 21, 26, 31, 35 and 36.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Requires:

Docs:

`SentryNdkCrashService.start` waited up to 10 s for the service to
connect and configure, on the thread that calls `SentryAndroid.init`,
usually the main thread. It now hands the app's ends to native right
away, and the service takes its ends when it connects. If it doesn't
connect within 10 s, its ends are closed so that native sends and the
crash handler fail at once, and a later connection reattaches.

Native init in sentry-native 1.0.0-beta.1 still waits for the daemon.
Nothing in the crash service needs API 30. Drop the check in
`SentryNdkOutproc.init()`, and pass the database directory to
`SentryNdk.createCrashShm()` so that the crash IPC falls back to a file
on kernels without memfd.

`Application.getProcessName()` needs API 28, so read the process name
from `/proc/self/cmdline` on older versions to skip SDK init in the
crash service process.
DO NOT MERGE (revert after releasing getsentry/sentry-native#2301)

`SentryNdk.createCrashShm(String)` is not in a sentry-native release
yet. Build `sentry-native-ndk-outproc` from the sentry-native branch
and publish it to Maven Local under a version that Maven Central does
not have, so that Gradle resolves the local build.
@jpnurmi
jpnurmi requested review from a team and adinauer as code owners November 16, 2026 08:58
@jpnurmi
jpnurmi requested review from romtsn and runningcode and removed request for a team November 16, 2026 08:58
@sentry

sentry Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.65.0 (1) release

⚙️ sentry-android Build Distribution Settings

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

A service that connected after the 10 s timeout reattached, but its
connection never counted as configured, so `onBindingDied` didn't bind
it again and out-of-process crash handling stayed down for the rest of
the session.
Below API 28, the check read `/proc/self/cmdline` on the thread that
calls `SentryAndroid.init`, usually the main thread, for every app,
which StrictMode flags as a disk read. Only apps with
`sentry-android-ndk-outproc` have the crash service process, so check
that its class is available first.
The connect timeout ran on the executor that also sends cached
envelopes, so a slow send could delay it. The timer executor is
dedicated to timeouts.
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: medium PR risk score: medium labels Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: high

For commit 3d985d9.

Main concerns: dependencies customers inherit, public contract, reach.

Rules that block low also fired:

  • R5: dependencies or bundled SDK versions changed: gradle/libs.versions.toml
  • R6: build or release configuration changed: .github/workflows/build.yml, gradle/libs.versions.toml

This label is a hint for reviewers, not an approval.

@romtsn romtsn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-approving, just one thing with freezing apps on API < 29 on the startup crash path

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Move the future item into its own separate section to reduce changelog
conflicts.
@github-actions github-actions Bot removed the risk: high PR risk score: high label Nov 20, 2026
@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 20, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

`SentryNdkCrashService.start` returns before the service connects, so
the service's ends of the crash IPC wait for the connection or the 10 s
timeout. `SentryNdkOutproc.close` only unbound the service, and a
non-restarting `Sentry.close` drops the pending timeout, which left the
descriptors to the finalizer. Close the ends that no connection took
when unbinding.
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: high PR risk score: high labels Nov 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 97adebf. Configure here.

`Context.unbindService` throws for a connection that is not registered,
which skipped closing the service's ends of the crash IPC.
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: high PR risk score: high labels Nov 20, 2026
The test relied on the manifest DSN, which `ContextUtils` caches
statically per Robolectric SDK sandbox. When another test class had
cached the app info without a DSN first, `SentryAndroid.init` failed.
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: high PR risk score: high labels Nov 20, 2026

@romtsn romtsn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to merge it :)

@jpnurmi jpnurmi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

TODO: I'll update the outproc ref here as soon as we've released sentry-native.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants