Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when MMKV.mmkvWithID(String mmapID) #210

Closed
vincentssn opened this issue Jan 29, 2019 · 19 comments
Closed

Crash when MMKV.mmkvWithID(String mmapID) #210

vincentssn opened this issue Jan 29, 2019 · 19 comments
Labels
bug Something isn't working

Comments

@vincentssn
Copy link

The language of MMKV

Java

The version of MMKV

v1.0.16

The platform of MMKV

Android

The installation of MMKV

Maven

What's the issue?

Post the outputs or screenshots for errors.

Explain what you want by example or code in English.
When the app gives out,we find the rate of ANR is increasing. The hint of stack of main thread from google play is below:

"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x736a8718 self=0xe6dfb000
| sysTid=17757 nice=0 cgrp=default sched=0/0 handle=0xeb08d4b8
| state=S schedstat=( 0 0 0 ) utm=23 stm=11 core=3 HZ=100
| stack=0xff298000-0xff29a000 stackSize=8MB
| held mutexes=
#00 pc 0000000000018e40 /system/lib/libc.so (syscall+28)
#1 pc 00000000000490ef /system/lib/libc.so (__pthread_mutex_lock_with_timeout(pthread_mutex_internal_t*, bool, timespec const*)+518)
#2 pc 000000000000fe6d /data/app/sg.bigo.live-2iOoZ9rP5uC4FrwyGiQtaQ==/lib/arm/libmmkv.so (???)
at com.tencent.mmkv.MMKV.getMMKVWithID (Native method)
at com.tencent.mmkv.MMKV.y (MMKV.java:86)

another case:

"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 obj=0x75b5c598 self=0xab35ff08
| sysTid=20586 nice=0 cgrp=default sched=0/0 handle=0xf7651b50
| state=S schedstat=( 392984120 914217 184 ) utm=29 stm=10 core=4 HZ=100
| stack=0xff76e000-0xff770000 stackSize=8MB
| held mutexes=
#00 pc 0000000000016998 /system/lib/libc.so (syscall+28)
#1 pc 000000000004208f /system/lib/libc.so (_ZL33__pthread_mutex_lock_with_timeoutP24pthread_mutex_internal_tPK8timespeci+326)
#2 pc 0000000000042245 /system/lib/libc.so (pthread_mutex_lock+26)
#3 pc 000000000000fe6d /data/app/sg.bigo.live-1/lib/arm/libmmkv.so (???)
at com.tencent.mmkv.MMKV.getMMKVWithID (Native method)
at com.tencent.mmkv.MMKV.y (MMKV.java:86)

@lingol
Copy link
Collaborator

lingol commented Jan 29, 2019

Call stack of other threads is needed. It's impossible to solve these lock-wait ANR without them.

@lingol
Copy link
Collaborator

lingol commented Jan 29, 2019

By the way, if you can provide MMKV's output to log cat, that will be nice.

@lingol
Copy link
Collaborator

lingol commented Jan 30, 2019

Is it possible that you has stored large data(10M+) inside MMKV?

@vincentssn
Copy link
Author

Because the anr info I can only get from google play. So i can't get log yet. But I notice that every anr case has a thread that blocked in libbreakpad.so.Does it help?
"pool-5-thread-1" prio=5 tid=21 Native
| group="main" sCount=1 dsCount=0 obj=0x32c0caf0 self=0xcaf06f00
| sysTid=21402 nice=0 cgrp=bg_non_interactive sched=0/0 handle=0xca87a920
| state=S schedstat=( 0 0 0 ) utm=0 stm=1 core=3 HZ=100
| stack=0xca778000-0xca77a000 stackSize=1038KB
| held mutexes=
#00 pc 00000000000177cc /system/lib/libc.so (syscall+28)
#1 pc 000000000004799f /system/lib/libc.so (pthread_join+146)
#2 pc 000000000000649c /data/app/com.my.app-2/lib/arm/libbreakpad.so (_Z12DumpCallbackRKN15google_breakpad18MinidumpDescriptorEPvb+600)
#3 pc 0000000000007944 /data/app/com.my.app-2/lib/arm/libbreakpad.so (_ZN15google_breakpad16ExceptionHandler12GenerateDumpEPNS0_12CrashContextE+560)
#4 pc 0000000000007d4c /data/app/com.my.app-2/lib/arm/libbreakpad.so (_ZN15google_breakpad16ExceptionHandler13SignalHandlerEiP7siginfoPv+168)
#5 pc 0000000000001f71 /system/bin/app_process32 (InvokeUserSignalHandler+156)
#6 pc 00000000001496e3 /system/lib/libart.so (_ZN3art12FaultManager11HandleFaultEiP7siginfoPv+222)
#7 pc 000000000001746c /system/lib/libc.so (???)
#8 pc 000000000001787c /system/lib/libc.so (memcpy+96)
#9 pc 000000000000f1cb /data/app/com.my.app-2/lib/arm/libmmkv.so (???)
at com.tencent.mmkv.MMKV.getMMKVWithID (Native method)
at com.tencent.mmkv.MMKV.y (MMKV.java:86)
at com.my.core.pref.z.y (MMKVWrapper.java:39)
at com.my.iheima.BaseLiveApplication.getSharedPreferences (BaseApplication.java:21)
at com.my.sdk.blivestat.l.x (BStatisPreference.java:155)
at com.my.sdk.blivestat.w.run (BGeneralEventStats.java:300)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:428)
at java.util.concurrent.FutureTask.run (FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607)
at java.lang.Thread.run (Thread.java:761)

@vincentssn
Copy link
Author

other thread blocked at
/system/lib/libc.so(_ZL33__pthread_mutex_lock_with_timeoutP24pthread_mutex_internal_tbPK8timespec+520)

@vincentssn
Copy link
Author

from the info above, it point out that the thread 'pool-5-thread-1' is blocked after using memcpy

@lingol
Copy link
Collaborator

lingol commented Feb 13, 2019

other thread blocked at
/system/lib/libc.so(_ZL33__pthread_mutex_lock_with_timeoutP24pthread_mutex_internal_tbPK8timespec+520)

I need more. Provide full stack of each thread if possible.

@vincentssn
Copy link
Author

full traces file has been sent to your e-mail @Tencent.

@lingol
Copy link
Collaborator

lingol commented Feb 13, 2019

Let me check one more thing, are you using com.tencent.mmkv:1.0.16, or com.tencent.mmkv-static:1.0.16?

@vincentssn
Copy link
Author

com.tencent.mmkv-static:1.0.16
to minimize the size of app.

@lingol
Copy link
Collaborator

lingol commented Feb 25, 2019

Hey, any update on your last release?

@pickpick12345
Copy link

I think this is because of a crash on LGH873 :

Thread 20 (crashed)
0 libc.so + 0x1787c
r0 = 0xe7ab8cc0 r1 = 0xe63f4fff r2 = 0x00000001 r3 = 0x00000000
r4 = 0xc7bfa0a8 r5 = 0x00000041 r6 = 0xe63f4fff r7 = 0xc7bfa078
r8 = 0xdce38300 r9 = 0xdce38314 r10 = 0x00000001 r12 = 0xe851c614
fp = 0x00000000 sp = 0xc7bfa060 lr = 0xe65a61cf pc = 0xe84ab87c
Found by: given as instruction pointer in context
1 libmmkv.so!MMBuffer::MMBuffer(void*, unsigned int, MMBufferCopyFlag) [MMBuffer.cpp : 36 + 0x3]
sp = 0xc7bfa068 pc = 0xe65a61cf
Found by: stack scanning
2 libmmkv.so!CodedInputData::readData() [CodedInputData.cpp : 95 + 0x5]
sp = 0xc7bfa080 pc = 0xe65a5245
Found by: stack scanning
3 libmmkv.so!MiniPBCoder::decodeOneMap(std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >, MMBuffer, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const, MMBuffer> > >&, unsigned int) [MiniPBCoder.cpp : 260 + 0x5]
sp = 0xc7bfa098 pc = 0xe65a5c6f
Found by: stack scanning
4 libmmkv.so!MiniPBCoder::decodeMap(std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >, MMBuffer, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const, MMBuffer> > >&, MMBuffer const&, unsigned int) [MiniPBCoder.cpp : 284 + 0x9]
sp = 0xc7bfa0d0 pc = 0xe65a5fe9
Found by: stack scanning
5 libmmkv.so!MMKV::loadFromFile() [MMKV.cpp : 357 + 0x7]
sp = 0xc7bfa100 pc = 0xe65a07dd
Found by: stack scanning
6 GeneralEventsPref + 0x2
sp = 0xc7bfa110 pc = 0xe63f0004
Found by: stack scanning
7 dalvik-main space (deleted) + 0x1856a322
sp = 0xc7bfa170 pc = 0x2b16a324
Found by: stack scanning
8 dalvik-main space (deleted) + 0x1856a322
sp = 0xc7bfa178 pc = 0x2b16a324
Found by: stack scanning
9 libmmkv.so!MMKV::MMKV(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, int, MMKVMode, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >) [MMKV.cpp : 109 + 0x5]
sp = 0xc7bfa1a0 pc = 0xe65a020f
Found by: stack scanning
10 dalvik-main space (deleted) + 0x1d104e
sp = 0xc7bfa1b4 pc = 0x12dd1050
Found by: stack scanning
11 libmmkv.so!MMKV::mmkvWithID(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, int, MMKVMode, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >) [MMKV.cpp : 231 + 0x7]
sp = 0xc7bfa1c8 pc = 0xe65a1149
Found by: stack scanning

@lingol
Copy link
Collaborator

lingol commented Mar 6, 2019

I think this is because of a crash on LGH873 :

Thread 20 (crashed)
0 libc.so + 0x1787c
r0 = 0xe7ab8cc0 r1 = 0xe63f4fff r2 = 0x00000001 r3 = 0x00000000
r4 = 0xc7bfa0a8 r5 = 0x00000041 r6 = 0xe63f4fff r7 = 0xc7bfa078
r8 = 0xdce38300 r9 = 0xdce38314 r10 = 0x00000001 r12 = 0xe851c614
fp = 0x00000000 sp = 0xc7bfa060 lr = 0xe65a61cf pc = 0xe84ab87c
Found by: given as instruction pointer in context
1 libmmkv.so!MMBuffer::MMBuffer(void*, unsigned int, MMBufferCopyFlag) [MMBuffer.cpp : 36 + 0x3]
sp = 0xc7bfa068 pc = 0xe65a61cf
Found by: stack scanning
2 libmmkv.so!CodedInputData::readData() [CodedInputData.cpp : 95 + 0x5]
sp = 0xc7bfa080 pc = 0xe65a5245
Found by: stack scanning
3 libmmkv.so!MiniPBCoder::decodeOneMap(std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >, MMBuffer, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const, MMBuffer> > >&, unsigned int) [MiniPBCoder.cpp : 260 + 0x5]
sp = 0xc7bfa098 pc = 0xe65a5c6f
Found by: stack scanning
4 libmmkv.so!MiniPBCoder::decodeMap(std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >, MMBuffer, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const, MMBuffer> > >&, MMBuffer const&, unsigned int) [MiniPBCoder.cpp : 284 + 0x9]
sp = 0xc7bfa0d0 pc = 0xe65a5fe9
Found by: stack scanning
5 libmmkv.so!MMKV::loadFromFile() [MMKV.cpp : 357 + 0x7]

Hi @pickpick12345 , can you send me that MMKV file which trigger this crash?
And if you can provide related logcat's output, it will be very helpful.
[email protected]

@pickpick12345
Copy link

This crash was caused by an online user, so we didn't get the logcat output or the specific data he wanted to save yet,but I sent crash files to your mailbox.

@lingol lingol changed the title ANR when MMKV.mmkvWithID(String mmapID) Crash when MMKV.mmkvWithID(String mmapID) Mar 6, 2019
@lingol lingol added the bug Something isn't working label Mar 6, 2019
@pickpick12345
Copy link

I found a possible reason .If the actual size saved in the header of the MMKV file records the wrong value for some reason and the MMKVHandler return OnErrorRecover, a similar crash would occur.

@lingol
Copy link
Collaborator

lingol commented Mar 7, 2019

I found a possible reason .If the actual size saved in the header of the MMKV file records the wrong value for some reason and the MMKVHandler return OnErrorRecover, a similar crash would occur.

Thanks for this input. I'll look into this case.
Though it's not the only case that will trigger such crash, I believe.

@lingol
Copy link
Collaborator

lingol commented Mar 7, 2019

I found a possible reason .If the actual size saved in the header of the MMKV file records the wrong value for some reason and the MMKVHandler return OnErrorRecover, a similar crash would occur.

Thanks for this input. I'll look into this case.
Though it's not the only case that will trigger such crash, I believe.

It's fixed with this commit. As has discussed before, it doesn't solve all those crash cases. For there were many cases that MMKV has finished loading without error, but crashed on getting a string value.

@lingol
Copy link
Collaborator

lingol commented Mar 14, 2019

I found a possible reason .If the actual size saved in the header of the MMKV file records the wrong value for some reason and the MMKVHandler return OnErrorRecover, a similar crash would occur.

Thanks for this input. I'll look into this case.
Though it's not the only case that will trigger such crash, I believe.

It's fixed with this commit. As has discussed before, it doesn't solve all those crash cases. For there were many cases that MMKV has finished loading without error, but crashed on getting a string value.

Released with v1.0.18.

@lingol
Copy link
Collaborator

lingol commented Mar 25, 2019

Close due to inactive.

@lingol lingol closed this as completed Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants