ANR: CacheFactory.build on the main thread waits for a Play Services Cronet install that never returns
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 15/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- mobile-dev, performance
Hướng nghiên cứu
Trace the wait from NavigatorLoader.kt:104 (createCacheHandle) into native CacheFactory.build, then read PlatformHttpService.kt, CronetClientDetail.kt and LazyEngine.kt (findCronetProvider, initializeProvider) where PlayServicesCronetProvider.isEnabled blocks on the Play services binder. Reproduce with the issue's latch snippet holding CronetProviderInstaller.zzc to see the 30 s main-thread stall. Done means a maintainer answer on the use_legacy_http_service flag plus a decision on timing out provider discovery or moving it off the CacheFactory.build path.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment
- Android OS version: 11 and 14
- Devices affected: an Android 14 in-vehicle display (Google Play services 26.43) and an Android 11 rugged phone. Most events come from the Android 14 device, where our app is a system app.
- Navigation SDK: 3.30.1 in production (
navigationcore:android-ndk27), with Maps 11.30.1, Common 24.30.1, Search 2.30.1. Also reproduced on Navigation 3.35.1, Maps 11.35.1, Common 24.35.1 (play-services-cronet18.1.0). - Setup:
MapboxNavigationApp.setup { ... }andMapboxNavigationApp.attachAllActivities(application)inApplication.onCreate.
Observed behavior
The app is frozen while an activity is created, and Android raises an ANR. We see 252 events from 71 devices. The main thread is always in CacheFactory.build:
android.app.Activity.dispatchActivityCreated
com.mapbox.navigation.core.internal.lifecycle.CarAppLifecycleOwner.changeState
com.mapbox.navigation.core.lifecycle.MapboxNavigationOwner$carAppLifecycleObserver$1.onStart (MapboxNavigationOwner.kt:28)
com.mapbox.navigation.core.MapboxNavigationProvider.create (MapboxNavigationProvider.kt:37)
com.mapbox.navigation.core.MapboxNavigation.<init> (MapboxNavigation.kt:548)
com.mapbox.navigation.core.NavigationComponentProvider.createNativeNavigator (NavigationComponentProvider.kt:78)
com.mapbox.navigation.navigator.internal.MapboxNativeNavigatorImpl.init (MapboxNativeNavigatorImpl.kt:127)
com.mapbox.navigation.navigator.internal.NavigatorLoader.createCacheHandle (NavigatorLoader.kt:104)
com.mapbox.navigator.CacheFactory.build (Native Method)
mapbox::navigation::CacheFactory::build
std::__ndk1::timed_mutex::lock
std::__ndk1::condition_variable::wait
pthread_cond_wait / __futex_wait_ex / syscall
When the full thread list was captured, the only blocked thread was a Mapbox worker creating the platform HTTP service:
"MB Worker U 2" (Blocked)
com.mapbox.common.PlatformHttpService.createPlatformHttpService (PlatformHttpService.kt:21)
com.mapbox.common.module.cronet.CronetClientDetail.<init> (CronetClientDetail.kt:29)
com.mapbox.common.module.cronet.LazyEngine.<init> (LazyEngine.kt:56)
com.mapbox.common.module.cronet.LazyEngine.initializeProvider (LazyEngine.kt:60)
com.mapbox.common.module.cronet.LazyEngineKt.findCronetProvider (LazyEngine.kt:180)
com.google.android.gms.net.PlayServicesCronetProvider.isEnabled
com.google.android.gms.net.PlayServicesCronetProvider.tryToInstallCronetProvider
com.google.android.gms.net.CronetProviderInstaller.zzc
com.google.android.gms.dynamite.DynamiteModule.load
android.content.ContentProviderClient$CursorWrapperInner.close
android.os.BinderProxy.transact <- binder call into Google Play services that does not return
Breadcrumbs around these events show Google Play services in trouble ("Google Play Services not available", "IGmsServiceBroker.getService failed") and Mapbox workers reporting long tasks, for example ConfigurationServiceWorker::sendConfigurationRequest took longer than 1 second: 20.1 s.
Analysis
PlayServicesCronetProvider.isEnabled()callstryToInstallCronetProvider()synchronously.CronetProviderInstaller.zzcholds a private static lock while it callsverifyGooglePlayServicesIsAvailableandDynamiteModule.load(..., "com.google.android.gms.cronet_dynamite"), both binder calls into Google Play services.LazyEngineKt.findCronetProvidercallsisEnabled()on every provider whilePlatformHttpService.createPlatformHttpServicebuilds the Cronet client.CacheFactory.buildon the main thread waits on a native mutex until the HTTP service exists. If Google Play services is slow, updating or hung, the main thread waits with it and the app ANRs.
Steps to reproduce
We could not hang Google Play services on a user build. Instead we simulated it by holding the installer's lock for 30 s, the state a hung Play services call leaves it in. The field name zzc is from play-services-cronet 18.1.0 in a non-minified debug build.
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
val held = CountDownLatch(1)
Thread {
val lock = Class.forName("com.google.android.gms.net.CronetProviderInstaller")
.getDeclaredField("zzc").apply { isAccessible = true }.get(null)!!
synchronized(lock) {
held.countDown()
Thread.sleep(30_000)
}
}.start()
held.await()
}
- Add the snippet above to the
Applicationof an app that sets upMapboxNavigationAppand attaches it to activities. - Cold-start the app and send a key event.
- The main thread stays in
CacheFactory.buildfor the whole 30 s and Android raises an ANR (am_anr). Cronet loads only after the lock is released.
Same result on Navigation 3.30.1 and 3.35.1, on Android 11 and 14.
Workaround
With this application meta-data the ANR does not happen under the same simulated hang, and maps, search, routing and offline tile region downloads keep working:
<meta-data
android:name="com.mapbox.common.use_legacy_http_service"
android:value="true" />
PlatformHttpService then builds MapboxHttpClient(OkHttpClientDetail()) and never creates CronetClientDetail. We found the flag in the Common SDK bytecode, not in the documentation.
Expected behavior
Creating MapboxNavigation on the main thread should not wait without bound for Google Play services. Cronet provider discovery could run off the path that CacheFactory.build waits on, have a timeout, or fall back to OkHttp when Play services does not answer.
Questions
- Is
com.mapbox.common.use_legacy_http_servicesupported, and will it stay in future Common releases? - Is excluding
com.google.android.gms:play-services-cronet(your guide "Removing the Google Play dependency") the recommended way to avoid this hang? - Can
CacheFactory.buildstop depending on the HTTP service being created, or can that creation stop blocking on Play services?
- Ngôn ngữ chính
- Kotlin
- Star
- 653
- Fork
- 322
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mapbox/mapbox-navigation-android
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 65/100
mapbox/mapbox-navigation-android#7852 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
mapbox/mapbox-navigation-android#7978 ·
-
Bug / Routing ErrorĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
mapbox/mapbox-navigation-android#7967 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
mapbox/mapbox-navigation-android#7966 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
mapbox/mapbox-navigation-android#7965 ·
Tất cả issue của mapbox/mapbox-navigation-android
Issue tương tự
-
[BUG] Issue reported from ReFraĐang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
IacobIonut01/ReFra#1515 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
openwatersio/slackwater-android#162 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
developmentwithyash/yaan#184 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
analytics
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
🐛 Type:Bug 📏 Size: S 🔧 State:In Progress 🔹 Priority: P2 - Medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
yeliqin666/xjtu-toolbox-android#623 · 1 bình luận ·