feat(react-native): detect and report Android ANRs - #391
Merged
Conversation
…info timestamps and dump attachment, rename debug option
melekr
approved these changes
Aug 27, 2026
… after at, keep native frame addresses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Android ANR detection with two modes, a threshold watchdog that reports mid-hang and ApplicationExitInfo records reported on the next launch, both carrying every thread's stack.
Changes
packages/react-native/srcBacktraceConfiguration.ts: adds theBacktraceAnrTypeenum andanrconfiguration options.BacktraceClient.ts: starts ANR reporting on initialize, picks watchdog or exit-info by type, disposes the handler.anr/AnrWatchdogHandler.ts: turns watchdog events into reports with main as the faulting thread and every other thread included, pauses the watchdog while backgrounded.anr/AnrReporter.ts: reads exit-info records on launch, sends oldest first, saves the last-timestamp cursor when a report is delivered or stored in the database for retry, attaches the OS dump.anr/AnrThreads.ts: attaches the non-main threads to a report, renaming duplicate thread names.anr/AnrException.ts: error namedHangfor classification.index.ts: exports the new enum and config type.packages/react-native/androidBacktraceAnrWatchdog.java: native module, starts/stops the watchdog, emits detection events with frames for every thread.BacktraceReactNative.java: addsgetAnrExitInfo, logs read failures at warn.ReactNativePackage.java: registers the watchdog module.AnrExitInfoReader.java: collects REASON_ANR records, returns them oldest first with attributes, message, raw trace, and parsed frames for the main thread and every other thread in the dump.anr/AnrWatchdog.java: watchdog thread, posts a ticker to the main looper, reports when the tick is missed past the timeout, one report per hang, optional debugger bail-out.anr/BacktraceThreadWatcher.java: tick counters the watchdog compares.anr/ExitInfo.java: ported from backtrace-android.anr/ExitInfoAdapter.java: ported from backtrace-android.anr/ProcessExitInfoProvider.java: ported from backtrace-android.anr/ActivityManagerExitInfoProvider.java: exit-record lookup, fetches all records instead of a fixed count.anr/ExitInfoStackTraceParser.java: parses the OS ANR dump into per-thread frames, keeps native-method, unknown-source, and fileless frames, null-guards unnamed threads.anr/AppExitInfoDetailsExtractor.java: extracts the ANR attributes and OS trace, attribute names match backtrace-android.anr/StackFrameMapper.java: maps stack traces to bridge frames and formatted text, keeps the native program counter asaddress.build.gradle: adds junit for unit tests.Tests
tests/anrReporterTests.spec.ts: covers ordering, cursor advancement, database-stored failures, attributes, attachment.tests/anrWatchdogHandlerTests.spec.ts: covers event handling, thread-name dedup, background pause, dispose.android/src/test/ExitInfoStackTraceParserTest.java: parser tests over a real ANR dump, covering the fileless and duplicate-name forms.android/src/test/resources/anrAppExitInfoStacktrace.txt: the dump fixture.Docs and CI
README.md: ANR Detection section..github/workflows/android.yml: runs the SDK unit tests before the emulator build.examples/sdk/reactNativeindex.js: enables ANR in the example.metro.config.js: pins a single react-native copy, a duplicate splits the JS event registry from the native one.ErrorGenerator.java: addsblockMainThreadto trigger a real ANR.src/actions/android/action.ts: the ANR action blocks the main thread instead of sleeping async.Note
A threshold report can be lost if the OS kills the app before the hang clears; the applicationExit type survives the kill.
ref: BT-7451