mapbox / mapbox/mapbox-maps-android

ANR in Mapbox native library during mutex lock (libmapbox-common.so, libmapbox-maps.so)

Open
#2,639 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

## Environment

- Android OS version: 11,12,13
- Devices affected: Samsung, Xiaomi, Vivo
- Maps SDK Version: 11.12.0

## Observed behavior and steps to reproduce

We're encountering a critical ANR on some devices, seemingly caused during native library initialization inside the Mapbox Maps SDK v10+. This issue happens while loading `libmapbox-common.so` and `libmapbox-maps.so`, particularly around a mutex lock on a background thread.

We are not calling `Mapbox.getInstance()` explicitly, and are using Mapbox v11.12.0 via `MapView` in Fragment.

## Expected behavior

The app should run smoothly without freezing or causing any delay in the UI thread. No ANR dialog should be shown.

## ANR Stack Trace (native)

```
(native):tid=9326 systid=9326
#00 pc 0x4deb0 libc.so (syscall + 32) (BuildId: 73e145ce4e1dfca57a8eaf6d29c1d3fe)
#01 pc 0x52954 libc.so (__futex_wait_ex(void volatile*, bool, int, bool, timespec const*) + 148) (BuildId: 73e145ce4e1dfca57a8eaf6d29c1d3fe)
#02 pc 0xb8050 libc.so (NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*) + 240) (BuildId: 73e145ce4e1dfca57a8eaf6d29c1d3fe)
#03 pc 0xc2bd0 split_config.arm64_v8a.apk!libc++_shared.so (std::__ndk1::mutex::lock() + 12) (BuildId: 25b13e08a3a359bf0ac835176dfbc89a7b30c1c4)
#04 pc 0x3bff34 split_config.arm64_v8a.apk!libmapbox-common.so + 16547840 (BuildId: 51df1ed7076fc3a6eeca0d8233cfe7d3fe326719)
#05 pc 0x3bfa40 split_config.arm64_v8a.apk!libmapbox-common.so + 16547840 (BuildId: 51df1ed7076fc3a6eeca0d8233cfe7d3fe326719)
#06 pc 0x4d3f30 split_config.arm64_v8a.apk!libmapbox-maps.so + 22708224 (BuildId: e187fc5229ec8674808855af4b2dd66a1d268e06)
#07 pc 0x4d4150 split_config.arm64_v8a.apk!libmapbox-maps.so + 22708224 (BuildId: e187fc5229ec8674808855af4b2dd66a1d268e06)
#08 pc 0x53ac0 linker64 (__dl__ZN6soinfo17call_constructorsEv + 628) (BuildId: 09543e0aac88c193fb3854ca8fc714c5)
#09 pc 0x3df3c linker64 (__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv + 2064) (BuildId: 09543e0aac88c193fb3854ca8fc714c5)
#10 pc 0x390fc linker64 (__loader_android_dlopen_ext + 84) (BuildId: 09543e0aac88c193fb3854ca8fc714c5)
#11 pc 0x110c libdl.so (android_dlopen_ext + 20) (BuildId: edfb970afd9e2ddf2187c7e62eae9389)
#12 pc 0x1c3d8 libnativeloader.so (android::NativeLoaderNamespace::Load(char const*) const + 196) (BuildId: b33846d3ef205beb574281c75443d859)
#13 pc 0xce70 libnativeloader.so (OpenNativeLibraryInNamespace + 68) (BuildId: b33846d3ef205beb574281c75443d859)
#14 pc 0xc598 libnativeloader.so (OpenNativeLibrary + 136) (BuildId: b33846d3ef205beb574281c75443d859)
#15 pc 0x45c478 libart.so (art::JavaVMExt::LoadNativeLibrary(_JNIEnv*, std::__1::basic_string, std::__1::allocator > const&, _jobject*, _jclass*, std::__1::basic_string, std::__1::allocator >*) + 2152) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#16 pc 0x51fc libopenjdkjvm.so (JVM_NativeLoad + 424) (BuildId: 84296c59dc4d78df6164e1451bf0b9d0)
#17 pc 0xab834 boot.oat (art_jni_trampoline + 148) (BuildId: cb3f7d683b4276aeb0f07ebac9fc30ac8eefbaa9)
#18 pc 0xc18c8 boot.oat (java.lang.Runtime.loadLibrary0 + 328) (BuildId: cb3f7d683b4276aeb0f07ebac9fc30ac8eefbaa9)
#19 pc 0xc3344 boot.oat (java.lang.Runtime.loadLibrary0 + 180) (BuildId: cb3f7d683b4276aeb0f07ebac9fc30ac8eefbaa9)
#20 pc 0xc6be0 boot.oat (java.lang.System.loadLibrary + 96) (BuildId: cb3f7d683b4276aeb0f07ebac9fc30ac8eefbaa9)
#21 pc 0xefc060 base.odex (com.mapbox.common.loader.MapboxLibraryLoader.load + 96)
#22 pc 0xf0e2d0 base.odex (com.mapbox.maps.loader.MapboxMapsInitializerImpl.create + 240)
#23 pc 0xc0a4c0 base.odex ([DEDUPED] + 48)
#24 pc 0xcc550c base.odex (androidx.startup.AppInitializer.doInitialize + 812)
#25 pc 0xcc624c base.odex (androidx.startup.AppInitializer.doInitialize + 220)
#26 pc 0xcc62f0 base.odex (androidx.startup.AppInitializer.initializeComponent + 48)
#27 pc 0xee9d98 base.odex (com.mapbox.common.BaseMapboxInitializer$Companion.init + 2072)
#28 pc 0xeeac8c base.odex (com.mapbox.common.BaseMapboxInitializer.create + 396)
#29 pc 0xeeb060 base.odex (com.mapbox.common.BaseMapboxInitializer.create + 48)
#30 pc 0xcc550c base.odex (androidx.startup.AppInitializer.doInitialize + 812)
#31 pc 0xcc608c base.odex (androidx.startup.AppInitializer.discoverAndInitialize + 812)
#32 pc 0xcc5c04 base.odex (androidx.startup.AppInitializer.discoverAndInitialize + 372)
#33 pc 0xcc6408 base.odex (androidx.startup.InitializationProvider.onCreate + 136)
#34 pc 0x6a71c0 boot-framework.oat (android.content.ContentProvider.attachInfo + 800) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#35 pc 0x6a7fd8 boot-framework.oat (android.content.ContentProvider.attachInfo + 56) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#36 pc 0x50ba0c boot-framework.oat (android.app.ActivityThread.installProvider + 1708) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#37 pc 0x50b0d4 boot-framework.oat (android.app.ActivityThread.installContentProviders + 788) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#38 pc 0x504e28 boot-framework.oat (android.app.ActivityThread.handleBindApplication + 5880) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#39 pc 0x4f98c8 boot-framework.oat (android.app.ActivityThread$H.handleMessage + 7960) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#40 pc 0x78d5bc boot-framework.oat (android.os.Handler.dispatchMessage + 188) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#41 pc 0x79080c boot-framework.oat (android.os.Looper.loopOnce + 1036) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#42 pc 0x790364 boot-framework.oat (android.os.Looper.loop + 516) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#43 pc 0x50d7f0 boot-framework.oat (android.app.ActivityThread.main + 800) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#44 pc 0x218be8 libart.so (art_quick_invoke_static_stub + 568) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#45 pc 0x28600c libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*) + 220) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#46 pc 0x62d0ec libart.so (_jobject* art::InvokeMethod<(art::PointerSize)8>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long) + 1388) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#47 pc 0x59b46c libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*) + 56) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#48 pc 0xb2f74 boot.oat (art_jni_trampoline + 132) (BuildId: cb3f7d683b4276aeb0f07ebac9fc30ac8eefbaa9)
#49 pc 0xae2bcc boot-framework.oat (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 140) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#50 pc 0xaebff8 boot-framework.oat (com.android.internal.os.ZygoteInit.main + 2376) (BuildId: 2de03480cfba9dcb99cb66a464e69569d8f81434)
#51 pc 0x218be8 libart.so (art_quick_invoke_static_stub + 568) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#52 pc 0x28600c libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*) + 220) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#53 pc 0x62d874 libart.so (art::JValue art::InvokeWithVarArgs(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, std::__va_list) + 452) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#54 pc 0x62dd68 libart.so (art::JValue art::InvokeWithVarArgs<_jmethodID*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, std::__va_list) + 96) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#55 pc 0x503df8 libart.so (art::JNI::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list) + 620) (BuildId: 4752fd49b3f5a76fd788c235cf2fb143)
#56 pc 0xb3bf8 libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...) + 124) (BuildId: 114b91edbaa34f59ff09b656c4c0d721)
#57 pc 0xc01e4 libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector const&, bool) + 852) (BuildId: 114b91edbaa34f59ff09b656c4c0d721)
#58 pc 0x25a8 app_process64 (main + 1360) (BuildId: f30f7754f376ddaa26066fb587c01d62)
#59 pc 0x4a068 libc.so (__libc_init + 100) (BuildId: 73e145ce4e1dfca57a8eaf6d29c1d3fe)

```

Please investigate whether there's a native mutex deadlock or race condition in the latest native libraries, possibly related to the shared `libc++_shared.so` or `libmapbox-common.so`. Any guidance or patch would be appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the AndroidX Startup entry points InitializationProvider and BaseMapboxInitializer, then follow MapboxMapsInitializerImpl.create into MapboxLibraryLoader.load. Compare the native loading stack involving libc++_shared.so, libmapbox-common.so, and libmapbox-maps.so across the reported Android versions and devices. Done means identifying a reproducible deadlock or race cause and documenting or validating a fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.