Skip to content

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

Open
jpnurmi wants to merge 10 commits into
v1from
jpnurmi/fix/native-android-21
Open

jpnurmi wants to merge 10 commits into
v1from
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.79%. Comparing base (5c6761b) to head (7a40d83).
⚠️ Report is 38 commits behind head on v1.

Additional details and impacted files
@@            Coverage Diff             @@
##               v1    #2301      +/-   ##
==========================================
+ Coverage   75.77%   75.79%   +0.02%     
==========================================
  Files         105      105              
  Lines       30828    30828              
  Branches     5745     5745              
==========================================
+ Hits        23359    23366       +7     
+ Misses       6036     6031       -5     
+ Partials     1433     1431       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

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 a22c3b7. Configure here.

Comment thread .github/workflows/e2e-test.yml Resolved
Comment thread tests/test_e2e_sentry.py Resolved
`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.
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.

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