Skip to content

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

Merged
markushi merged 8 commits into
mainfrom
fix/anr-tombstone-main-thread-detection
Jul 9, 2026
Merged

fix(anr): Detect main thread from tombstone via pid matching thread id#5742
markushi merged 8 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 318.53 ms 402.32 ms 83.79 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
bbc35bb 324.88 ms 425.73 ms 100.85 ms
abfcc92 304.04 ms 370.33 ms 66.29 ms
94bff8d 313.23 ms 352.77 ms 39.54 ms
fcec2f2 311.35 ms 384.94 ms 73.59 ms
d15471f 304.55 ms 408.43 ms 103.87 ms
4c04bb8 307.93 ms 362.34 ms 54.41 ms
b936425 302.69 ms 372.86 ms 70.17 ms
d501a7e 314.55 ms 343.34 ms 28.79 ms
72020f8 312.32 ms 370.94 ms 58.62 ms
6b019b7 319.84 ms 333.15 ms 13.31 ms

App size

Revision Plain With Sentry Diff
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
94bff8d 1.58 MiB 2.20 MiB 635.37 KiB
fcec2f2 1.58 MiB 2.12 MiB 551.51 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
4c04bb8 0 B 0 B 0 B
b936425 0 B 0 B 0 B
d501a7e 0 B 0 B 0 B
72020f8 1.58 MiB 2.19 MiB 620.21 KiB
6b019b7 0 B 0 B 0 B

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
2e04adf 314.06 ms 365.72 ms 51.66 ms

App size

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

@markushi markushi marked this pull request as ready for review July 8, 2026 13:33
@markushi markushi merged commit d99fe33 into main Jul 9, 2026
69 of 70 checks passed
@markushi markushi deleted the fix/anr-tombstone-main-thread-detection branch July 9, 2026 07:29
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