Skip to content

fix(android): handle unwinder allocation failures - #2239

Merged
jpnurmi merged 5 commits into
masterfrom
jpnurmi/fix/unwinder-alloc
Oct 26, 2026
Merged

jpnurmi merged 5 commits into
masterfrom
jpnurmi/fix/unwinder-alloc

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

libunwindstack throws std::bad_alloc from Maps::Parse when an allocation fails, e.g. at the mapping limit. Uncaught on the inproc handler thread, it aborted the process, and the tombstone reported the abort instead of the original crash.

Catch exceptions in sentry__unwind_stack_libunwindstack and fall back to the crash PC, as for unparsable maps. Allocate the handler thread's C++ exception state at startup with sentry__unwind_init, because the NDK's C++ runtime aborts if the first throw on a thread fails to allocate it.

Fixes: #2235

libunwindstack throws `std::bad_alloc` from `Maps::Parse` when an
allocation fails, e.g. at the mapping limit. Uncaught on the inproc
handler thread, it aborted the process, and the tombstone reported the
abort instead of the original crash.

Catch exceptions in `sentry__unwind_stack_libunwindstack` and fall back
to the crash PC, as for unparsable maps. Allocate the handler thread's
C++ exception state at startup with `sentry__unwind_init`, because the
NDK's C++ runtime aborts if the first throw on a thread fails to
allocate it.

Fixes: #2235
Allocate the thread's C++ exception state with `__cxa_get_globals`
instead of a throw/catch. Per new thread on a Pixel 8 Pro (NDK 29,
`c++_static`), averaged over 200 threads:

- throw/catch: ~120 us, ~300 us for the first throw in the process
- `__cxa_get_globals`: ~7 us
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 75.70%. Comparing base (8d90c56) to head (dd867bb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2239      +/-   ##
==========================================
+ Coverage   75.63%   75.70%   +0.06%     
==========================================
  Files         103      103              
  Lines       28263    28266       +3     
  Branches     5180     5180              
==========================================
+ Hits        21378    21400      +22     
+ Misses       5540     5522      -18     
+ Partials     1345     1344       -1     
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

@jpnurmi
jpnurmi merged commit b191093 into master Oct 26, 2026
70 checks passed
@jpnurmi
jpnurmi deleted the jpnurmi/fix/unwinder-alloc branch October 26, 2026 12:39
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.

Android: in-process crash handler aborts with std::bad_alloc while parsing process maps, losing the original crash

2 participants