Skip to content

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

Merged
jpnurmi merged 17 commits into
mainfrom
jpnurmi/fix/native-android-21
Nov 25, 2026
Merged

jpnurmi merged 17 commits into
mainfrom
jpnurmi/fix/native-android-21

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

📜 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.1 (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: medium

For commit 760ba9b.

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

Rules that block low also fired:

  • R5: dependencies or bundled SDK versions changed: gradle/libs.versions.toml
  • R6: build or release configuration changed: 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.

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: high PR risk score: high labels Nov 25, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 25, 2026
@jpnurmi
jpnurmi merged commit a847563 into main Nov 25, 2026
50 checks passed
@jpnurmi
jpnurmi deleted the jpnurmi/fix/native-android-21 branch November 25, 2026 09:51
jpnurmi added a commit to getsentry/sentry-native that referenced this pull request Nov 26, 2026
Replace the PR branch ref (getsentry/sentry-java#6614) with the
released 8.66.0 tag so the Android outproc e2e job tests against
a fixed sentry-java release:

- https://github.com/getsentry/sentry-java/releases/tag/8.66.0
jpnurmi added a commit to getsentry/sentry-docs that referenced this pull request Dec 1, 2026
…#20818)

<!-- Keep the urgency section so automation can prioritize this PR. You
may delete other sections you don't need. -->

## DESCRIBE YOUR PR

The out-of-process crash service now runs on all Android versions that
the SDK supports:
- getsentry/sentry-java#6614

## IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
Select exactly one option. For deadlines, replace `YYYY-MM-DD` with the
due date. You can update this information later by editing the PR
description.

- [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD
- [ ] Other deadline: YYYY-MM-DD
- [x] No deadline: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
supplied a deadline.

Thanks in advance for your help!

## PRE-MERGE CHECKLIST

_Make sure you've checked the following before merging your changes:_

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

## LEGAL BOILERPLATE

<!-- Sentry employees and contractors can delete or ignore this section.
-->

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.

## EXTRA RESOURCES

- [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
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.

3 participants