Skip to content

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

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

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

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

💡 Before, Native on Android required API 30+. Now, it works with the same API 21+ as Inproc.

The crash service's shared memory used memfd_create, which needs Linux 3.17+. Devices that launched before API 26 may run older kernels, where native SDK init failed and native crash reporting was disabled. SentryNdk.createCrashShm(String) now falls back to an unlinked file in the database directory, preallocated with posix_fallocate() so that a full disk fails at init instead of raising SIGBUS on a later write. createCrashShm() keeps using memfd only.

Required for, and to be merged after agreeing on:

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.83%. Comparing base (db67673) to head (cb7af51).

Additional details and impacted files
@@                      Coverage Diff                       @@
##           jpnurmi/fix/native-recover    #2301      +/-   ##
==============================================================
+ Coverage                       75.64%   75.83%   +0.19%     
==============================================================
  Files                             105      105              
  Lines                           30985    30989       +4     
  Branches                         5784     5785       +1     
==============================================================
+ Hits                            23439    23501      +62     
+ Misses                           6115     6057      -58     
  Partials                         1431     1431              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpnurmi
jpnurmi force-pushed the jpnurmi/fix/native-android-21 branch from c068b33 to a22c3b7 Compare November 11, 2026 17:49

@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.

Comment thread .github/workflows/e2e-test.yml Resolved
Comment thread tests/test_e2e_sentry.py Resolved
jpnurmi added a commit to getsentry/sentry-java that referenced this pull request Nov 16, 2026
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.

@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 7f9923a. Configure here.

Comment thread src/backends/native/sentry_crash_ipc.c Resolved
@jpnurmi

jpnurmi commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Applied Roman's suggestions from getsentry/sentry-java#6614 (comment)

`memfd_create` needs Linux 3.17, so creating the crash service's
shared memory failed on older kernels, and the SDK disabled native
crash reporting.

When `memfd_create` fails, create an unlinked file in the database
directory instead. Preallocate it with `posix_fallocate()`, because a
sparse file raises `SIGBUS` on write when the disk is full. Java passes
the directory to the new `SentryNdk.createCrashShm(String)` overload,
and `createCrashShm()` keeps using memfd only.
The overload without a database directory has no file fallback, so it
needs a kernel with memfd rather than a specific API level.
Match the Android API levels and NDK versions in `ci.yml`. The crash
IPC now works without memfd, so drop the fixture's API 30 `minSdk`
and the tests' API 30 skips.
The API 21 and 26 e2e jobs need the sentry-java side of running the
crash service below API 30.
API 31 tombstones leave dex frames unnamed, so the merged event has no
Java method names. Check them only on later API levels.

The fixture crashed 1 s after setting the scope, but sentry-java syncs
the scope to native on its single-threaded executor, behind the startup
work of the tombstone integration. Now that the crash service starts
without waiting, that work can still run when the crash fires, and the
event misses the `test.id` tag. Queue the crash on the executor, so
that it follows the scope sync.

Print logcat when an Android e2e test fails.
`has_native` was false below API 23, so the API 21 e2e job skipped
all Android tests and never exercised the file fallback for crash IPC.
API 21 is the minimum, so drop the Android clause.
A non-UTF-8 byte in `adb logcat` output raised `UnicodeDecodeError`
in the fixture teardown and lost the logcat dump of a failed test.
The API 23 skip blamed `process_vm_readv`, but below API 23
`sentry__process_vm_readv()` calls the raw syscall.
The e2e tests do not use Google Play services. Use the smaller AOSP
images, like the regular Android CI jobs.
Below API 29, the app receives the crash service connection on its main
thread. A native crash on the main thread before the daemon attached
froze the app for 10 s, waiting for a daemon that couldn't attach, and
then chained. Don't notify it in that case, so the crash chains at once.
A crash on another thread still waits, since the main thread is free to
attach the daemon.
A crash on the main thread checks whether the crash service attached
without the writer lock. A concurrent send could read the ready signal
between the crash handler's poll and read, and the handler then blocked
on the drained pipe. Poll without reading, so that every caller sees the
signal. A reattach replaces the pipe, which drops the old signal.
The e2e fixture crashed 1 s after `SentryAndroid.init`, so no test
covered a crash on the main thread before the crash service connects.
Add an early variant that crashes as soon as the scope is synced. It
runs on API 29 and later, where the service connects on a binder thread
while the crash handler waits.
Crash synchronously right after init, so that below API 29 the main
looper cannot connect the crash service first, and relaunch the app
to send the crash.
@jpnurmi
jpnurmi changed the base branch from v1 to jpnurmi/fix/native-recover November 20, 2026 14:12
@jpnurmi
jpnurmi force-pushed the jpnurmi/fix/native-android-21 branch from 0c9e82f to cb7af51 Compare November 20, 2026 14:12
@jpnurmi
jpnurmi added this pull request to stack #2331 November 20, 2026 14:13

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants