Skip to content

fix(gestures): Replace GestureDetectorCompat with lightweight detector to fix ANR#5138

Open
romtsn wants to merge 5 commits intomainfrom
rz/fix/anr-gesture-detector
Open

fix(gestures): Replace GestureDetectorCompat with lightweight detector to fix ANR#5138
romtsn wants to merge 5 commits intomainfrom
rz/fix/anr-gesture-detector

Conversation

@romtsn
Copy link
Member

@romtsn romtsn commented Mar 2, 2026

Summary

  • Replace GestureDetectorCompat with a custom lightweight SentryGestureDetector in SentryWindowCallback to fix ANR SDK-CRASHES-JAVA-596 (175K+ occurrences, 574 users)
  • GestureDetectorCompat internally uses Handler.sendMessage/removeMessages which acquires a synchronized lock on the main thread's MessageQueue, plus recordGestureClassification() triggers IPC/binder calls — both cause contention under load
  • The new detector only implements click, scroll, and fling detection (the only gestures SentryGestureListener uses), eliminating all Handler scheduling, MessageQueue lock contention, and IPC overhead

Test plan

  • Added SentryGestureDetectorTest with 7 test cases: tap, no-tap, scroll with deltas, fling, slow release, cancel cleanup, sequential gesture reset
  • Existing SentryWindowCallbackTest (4 tests) passes
  • Existing SentryGestureListenerTest suite passes
  • ./gradlew :sentry-android-core:testDebugUnitTest passes
  • Manual testing on Android device

🤖 Generated with Claude Code

romtsn and others added 2 commits March 2, 2026 21:03
…stureDetector to fix ANR

GestureDetectorCompat internally uses Handler.sendMessage/removeMessages which
acquires a synchronized lock on the main thread MessageQueue, plus
recordGestureClassification triggers IPC calls. This caused ANRs under load
(SDK-CRASHES-JAVA-596, 175K+ occurrences).

Replace with a minimal custom detector that only detects click, scroll, and
fling without any Handler scheduling, MessageQueue contention, or IPC overhead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (otel) Create sentry-opentelemetry-otlp module for combining OpenTelemetry SDK OTLP export with Sentry SDK by adinauer in #5100
  • (screenshot) Add screenshot masking using view hierarchy by romtsn in #5077

Bug Fixes 🐛

  • (gestures) Replace GestureDetectorCompat with lightweight detector to fix ANR by romtsn in #5138
  • (transport) Handle HTTP 413 with actionable log and use send_error for HTTP errors by adinauer in #5115
  • Trim DSN string before URI parsing by adinauer in #5113
  • Safe unregister SystemEventsBroadcastReceiver by kollesnica1337 in #5106

Internal Changes 🔧

Deps

  • Bump getsentry/craft from 2.21.7 to 2.23.1 by dependabot in #5129
  • Update Native SDK to v0.13.1 by github-actions in #5104
  • Bump actions/upload-artifact from 6 to 7 by dependabot in #5130
  • Bump actions/download-artifact from 7 to 8 by dependabot in #5132
  • Bump gradle/actions from 5.0.1 to 5.0.2 by dependabot in #5131
  • Bump github/codeql-action from 4.32.2 to 4.32.4 by dependabot in #5109
  • Bump getsentry/craft from 2.21.2 to 2.21.7 by dependabot in #5110

🤖 This preview updates automatically when you update the PR.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 382.98 ms 473.75 ms 90.77 ms
Size 1.58 MiB 2.29 MiB 723.82 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
e59e22a 329.74 ms 383.31 ms 53.57 ms
fc5ccaf 270.49 ms 363.90 ms 93.41 ms
d15471f 361.89 ms 378.07 ms 16.18 ms
d15471f 322.58 ms 396.08 ms 73.50 ms
abfcc92 304.04 ms 370.33 ms 66.29 ms
91bb874 310.68 ms 359.24 ms 48.56 ms
ab8a72d 316.24 ms 356.38 ms 40.14 ms
d15471f 286.65 ms 314.68 ms 28.03 ms
6727e14 337.22 ms 373.94 ms 36.71 ms
f064536 329.00 ms 395.62 ms 66.62 ms

App size

Revision Plain With Sentry Diff
e59e22a 1.58 MiB 2.20 MiB 635.34 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
ab8a72d 1.58 MiB 2.12 MiB 551.55 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
6727e14 1.58 MiB 2.28 MiB 718.64 KiB
f064536 1.58 MiB 2.20 MiB 633.90 KiB

Previous results on branch: rz/fix/anr-gesture-detector

Startup times

Revision Plain With Sentry Diff
3c64e61 338.52 ms 430.68 ms 92.16 ms
99696ad 313.46 ms 354.00 ms 40.54 ms

App size

Revision Plain With Sentry Diff
3c64e61 1.58 MiB 2.29 MiB 723.86 KiB
99696ad 1.58 MiB 2.29 MiB 723.83 KiB

…velocity data

Matches GestureDetector behavior: if consecutive ACTION_DOWN events
arrive without an intervening ACTION_UP/ACTION_CANCEL, stale motion
data could bleed into fling detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

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.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

…check

UserInteractionIntegration gated itself on GestureDetectorCompat being
available via classloader check, but SentryGestureDetector only uses
Android SDK classes. Remove the check so the integration works without
androidx.core. Also remove the stale proguard -keep rule.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant