Skip to content

Fix startup ANR from eager WebView user agent#2156

Merged
jocmp merged 2 commits into
mainfrom
jc/2145/lazy-user-agent
Jun 14, 2026
Merged

Fix startup ANR from eager WebView user agent#2156
jocmp merged 2 commits into
mainfrom
jc/2145/lazy-user-agent

Conversation

@jocmp

@jocmp jocmp commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Some users hit an ANR on launch the app hangs on the launcher icon then quits. Reported in discussion #2145 but Crashlytics shows it across several devices.

The top ANR issue blames CommonModule.kt which is the AccountManager Koin singleton initializer. The thread dump:

at android.webkit.WebSettings.getDefaultUserAgent (WebSettings.java:1365)
at com.capyreader.app.CommonModuleKt.common$lambda$0$4 (CommonModule.kt:34)
at org.koin.core.instance.SingleInstanceFactory.create
at org.koin.mp.KoinPlatformTools.synchronized   // holds Koin's single lock

WebSettings.getDefaultUserAgent() loads the WebView/Chromium provider which is slow to initialize.

The fix is to lazily resolve the user agent at network time in ArticleContent and FaviconFinder.

Additionally, this moves refresh scheduling off app boot which removes the background thread that was in contention for the singleton lock.

@jocmp jocmp force-pushed the jc/2145/lazy-user-agent branch 3 times, most recently from 2956681 to 7c65fd6 Compare June 14, 2026 18:06
WebSettings.getDefaultUserAgent loads the WebView provider, which is
slow to initialize on some devices. It was evaluated eagerly inside the
AccountManager Koin singleton's initializer, so it ran while holding
Koin's single-creation lock. A background thread stalling there blocked
the main thread resolving the same singleton, causing startup ANRs
(discussion 2145).

userAgent is only needed at network time (ArticleContent, FaviconFinder),
so it's a () -> String invoked at request time, off the main thread.
@jocmp jocmp force-pushed the jc/2145/lazy-user-agent branch from 7c65fd6 to 2e4bffc Compare June 14, 2026 18:06
@jocmp jocmp merged commit 7a8fe72 into main Jun 14, 2026
2 checks passed
@jocmp jocmp deleted the jc/2145/lazy-user-agent branch June 14, 2026 18:12
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