Skip to content

fix(anr): Detect main thread from tombstone via pid matching thread id#5742

Open
markushi wants to merge 7 commits into
mainfrom
fix/anr-tombstone-main-thread-detection
Open

fix(anr): Detect main thread from tombstone via pid matching thread id#5742
markushi wants to merge 7 commits into
mainfrom
fix/anr-tombstone-main-thread-detection

Conversation

@markushi

@markushi markushi commented Jul 8, 2026

Copy link
Copy Markdown
Member

📜 Description

Analogous to the ANR thread-dump fix in #5733, applied it to the tombstone (ApplicationExitInfo native crash) path as well.

Changes

  • Mark the tombstone thread whose id equals the process id as the main thread and set its name to "main".

No public API change.

💡 Motivation and Context

When the OS names the main thread after the process (or leaves it unnamed), native crashes were not attributed to the main thread. Matching on id == pid is robust and does not depend on the (truncatable) process name.

💚 How did you test it?

  • Added a unit test to TombstoneParserTest covering main-thread detection and name normalization, with separate crashed/background threads to verify independence.
  • Strengthened the existing snapshot test to assert the main thread is detected from real tombstone data.

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

🔮 Next steps

markushi and others added 2 commits July 8, 2026 09:55
On Linux/Android the main thread's kernel thread id always equals the process
id, so match a tombstone thread whose id equals the pid as the main thread and
normalize its name back to "main". This is more robust than relying on the
OS-assigned thread name, which some versions/OEMs replace with the process name.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sentry

sentry Bot commented Jul 8, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 314.06 ms 365.72 ms 51.66 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
4c04bb8 350.71 ms 413.63 ms 62.92 ms
bb0ff41 315.84 ms 350.76 ms 34.92 ms
7c1a728 289.46 ms 368.15 ms 78.69 ms
ff8eea4 313.42 ms 337.08 ms 23.66 ms
bbc35bb 298.53 ms 372.17 ms 73.64 ms
91bb874 311.00 ms 363.47 ms 52.47 ms
abfcc92 337.38 ms 427.39 ms 90.00 ms
ae7fed0 293.84 ms 380.22 ms 86.38 ms
3998a95 415.94 ms 478.54 ms 62.60 ms
d15471f 307.28 ms 381.85 ms 74.57 ms

App size

Revision Plain With Sentry Diff
4c04bb8 0 B 0 B 0 B
bb0ff41 0 B 0 B 0 B
7c1a728 0 B 0 B 0 B
ff8eea4 1.58 MiB 2.28 MiB 718.64 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
ae7fed0 1.58 MiB 2.12 MiB 551.77 KiB
3998a95 1.58 MiB 2.10 MiB 532.96 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB

Previous results on branch: fix/anr-tombstone-main-thread-detection

Startup times

Revision Plain With Sentry Diff
81a3256 450.06 ms 581.68 ms 131.62 ms

App size

Revision Plain With Sentry Diff
81a3256 0 B 0 B 0 B

@markushi markushi marked this pull request as ready for review July 8, 2026 13:33
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.

2 participants