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 on mutiple thread #130

Closed
BrotooLu opened this issue Nov 30, 2018 · 9 comments
Closed

crash on mutiple thread #130

BrotooLu opened this issue Nov 30, 2018 · 9 comments

Comments

@BrotooLu
Copy link

The language of MMKV

Java

The version of MMKV

v1.0.13

The platform of MMKV

Android

The installation of MMKV

Git clone

What's the issue?

crash type one: input is not valid Modified UTF-8
crash type two: CodedInputData::CodedInputData(const void *, int32_t): assertion "m_ptr" failed'

code:
private static final int COUNT = 1000;
private static final int THREAD_COUNT = 4;
private static final String ID = "test-thread-safe";
private static final String KEY = "key-string";
private static final String VAL = "虽然雷霆实力占优,又是主场作战,不过开场后命中率不高,打完七分钟两";

Runnable task = new Runnable() {
@OverRide
public void run() {
MMKV mmkv = MMKV.mmkvWithID(ID);
for (int i = 0; i < COUNT; ++i) {
mmkv.putString(KEY, VAL);
mmkv.getString(KEY, null);
mmkv.remove(KEY);
}
}
};

for (int i = 0; i < THREAD_COUNT; ++i) {
new Thread(task, "tt-" + i).start();
}

11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal continuation byte 0x70
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] string: '虽然雷霆实力占优,又是主场作战,不过开场后命中率不高,打完七分�p'
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] in call to NewStringUTF
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] from java.lang.String com.tencent.mmkv.MMKV.decodeString(long, java.lang.String, java.lang.String)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] "tt-1" prio=5 tid=15 Runnable
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] | group="main" sCount=0 dsCount=0 obj=0x12cf21c0 self=0x5584482c00
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] | sysTid=24474 nice=0 cgrp=default sched=0/0 handle=0x7f5c9ce450
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] | state=R schedstat=( 3312344 0 18 ) utm=0 stm=0 core=2 HZ=100
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] | stack=0x7f5c8cc000-0x7f5c8ce000 stackSize=1037KB
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] | held mutexes= "mutator lock"(shared held)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #00 pc 000000000048be48 /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiPKcPNS_9ArtMethod
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #1 pc 000000000045b008 /system/lib64/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+220)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #2 pc 000000000030f3e0 /system/lib64/libart.so (ZN3art9JavaVMExt8JniAbortEPKcS2+1000)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #3 pc 000000000030fc98 /system/lib64/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+116)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #4 pc 0000000000144ff4 /system/lib64/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+144)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #5 pc 000000000014d228 /system/lib64/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE.constprop.116+1
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #6 pc 0000000000156470 /system/lib64/libart.so (_ZN3art8CheckJNI12NewStringUTFEP7_JNIEnvPKc+468)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #7 pc 0000000000014090 /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (_ZN7_JNIEnv12NewStringUTFEPKc+48)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #8 pc 0000000000010f0c /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (???)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #9 pc 0000000000012354 /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (Java_com_tencent_mmkv_MMKV_decodeString+264)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #10 pc 000000000029db8c /data/app/com.tencent.mmkvdemo-2/oat/arm64/base.odex (java.lang.String com.tencent.mmkv.MMKV.decodeString(long, java
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #11 pc 00000000002a3504 /data/app/com.tencent.mmkvdemo-2/oat/arm64/base.odex (java.lang.String com.tencent.mmkv.MMKV.getString(java.lang.Str
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #12 pc 00000000002b3c08 /data/app/com.tencent.mmkvdemo-2/oat/arm64/base.odex (void com.tencent.mmkvdemo.MainActivity$1$1.run()+348)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] native: #13 pc 0000000000035ec4 /data/dalvik-cache/arm64/system@framework@boot.oat (???)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] at com.tencent.mmkv.MMKV.decodeString(Native method)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] at com.tencent.mmkv.MMKV.getString(MMKV.java:373)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] at com.tencent.mmkvdemo.MainActivity$1$1.run(MainActivity.java:79)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410] at java.lang.Thread.run(Thread.java:818)
11-30 14:52:16.587 24451-24474/com.tencent.mmkvdemo A/art: art/runtime/java_vm_ext.cc:410]
11-30 14:52:16.615 14064-14064/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-30 14:52:16.615 14064-14064/? A/DEBUG: Build fingerprint: 'Coolpad/Cool1_CN/cool_c1:6.0.1/ZCXCNCT5902606201S/0002043:user/release-keys'
11-30 14:52:16.615 14064-14064/? A/DEBUG: Revision: '0'
11-30 14:52:16.615 14064-14064/? A/DEBUG: ABI: 'arm64'
11-30 14:52:16.616 14064-14064/? A/DEBUG: pid: 24451, tid: 24476, name: tt-3 >>> com.tencent.mmkvdemo <<<
11-30 14:52:16.616 14064-14064/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
11-30 14:52:16.630 14064-14064/? A/DEBUG: Abort message: '/Users/bro2/priv/MMKV/Android/MMKV/mmkv/src/main/cpp/CodedInputData.cpp:30: CodedInputData::CodedInputData(const void *, int32_t): assertion "m_ptr" failed'
11-30 14:52:16.630 14064-14064/? A/DEBUG: x0 0000000000000000 x1 0000000000005f9c x2 0000000000000006 x3 0000000000000000
11-30 14:52:16.630 14064-14064/? A/DEBUG: x4 0000000000000000 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
11-30 14:52:16.630 14064-14064/? A/DEBUG: x8 0000000000000083 x9 6860651f2171736f x10 7f7f7f7f7f7f7f7f x11 0101010101010101
11-30 14:52:16.630 14064-14064/? A/DEBUG: x12 0000007f7c6107c8 x13 8477af77e68ef8c4 x14 8477af77e68ef8c4 x15 00217f217f8a203b
11-30 14:52:16.630 14064-14064/? A/DEBUG: x16 0000007f7c60a6a8 x17 0000007f7c5ccb9c x18 0000007f78228000 x19 0000007f5c7c4510
11-30 14:52:16.630 14064-14064/? A/DEBUG: x20 0000007f5c7c4450 x21 0000000000000000 x22 0000000000000006 x23 0000007f5c7c4208
11-30 14:52:16.630 14064-14064/? A/DEBUG: x24 0000007f5c7c42b8 x25 0000007f5c7c42d8 x26 0000000071668cbd x27 00000000711dafb8
11-30 14:52:16.630 14064-14064/? A/DEBUG: x28 00000055847d6790 x29 0000007f5c7c39c0 x30 0000007f7c5ca338
11-30 14:52:16.630 14064-14064/? A/DEBUG: sp 0000007f5c7c39c0 pc 0000007f7c5ccba4 pstate 0000000020000000
11-30 14:52:16.634 14064-14064/? A/DEBUG: backtrace:
11-30 14:52:16.634 14064-14064/? A/DEBUG: #00 pc 000000000006aba4 /system/lib64/libc.so (tgkill+8)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #1 pc 0000000000068334 /system/lib64/libc.so (pthread_kill+68)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #2 pc 00000000000212b8 /system/lib64/libc.so (raise+28)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #3 pc 000000000001ba58 /system/lib64/libc.so (abort+60)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #4 pc 000000000001eea0 /system/lib64/libc.so (__libc_fatal+128)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #5 pc 000000000001bb30 /system/lib64/libc.so (__assert2+40)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #6 pc 000000000002d86c /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (_ZN14CodedInputDataC1EPKvi+88)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #7 pc 000000000002ed30 /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (_ZN11MiniPBCoderC1EPK8MMBuffer+104)
11-30 14:52:16.634 14064-14064/? A/DEBUG: #8 pc 0000000000031c60 /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (_ZN11MiniPBCoder12decodeStringERK8MMBuffer+44)
11-30 14:52:16.635 14064-14064/? A/DEBUG: #9 pc 00000000000231b8 /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (ZN4MMKV15getStringForKeyERKNSt6__ndk112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERS6+256)
11-30 14:52:16.635 14064-14064/? A/DEBUG: #10 pc 0000000000012338 /data/app/com.tencent.mmkvdemo-2/lib/arm64/libmmkv.so (Java_com_tencent_mmkv_MMKV_decodeString+236)
11-30 14:52:16.635 14064-14064/? A/DEBUG: #11 pc 00000000006fab8c /data/app/com.tencent.mmkvdemo-2/oat/arm64/base.odex (offset 0x45d000) (java.lang.String com.tencent.mmkv.MMKV.decodeString(long, java.lang.String, java.lang.String)+192)
11-30 14:52:16.635 14064-14064/? A/DEBUG: #12 pc 0000000000700504 /data/app/com.tencent.mmkvdemo-2/oat/arm64/base.odex (offset 0x45d000) (java.lang.String com.tencent.mmkv.MMKV.getString(java.lang.String, java.lang.String)+104)
11-30 14:52:16.635 14064-14064/? A/DEBUG: #13 pc 0000000000710c08 /data/app/com.tencent.mmkvdemo-2/oat/arm64/base.odex (offset 0x45d000) (void com.tencent.mmkvdemo.MainActivity$1$1.run()+348)
11-30 14:52:16.635 14064-14064/? A/DEBUG: #14 pc 0000000073574ec4 /data/dalvik-cache/arm64/system@framework@boot.oat (offset 0x227e000)

@lingol
Copy link
Collaborator

lingol commented Nov 30, 2018

I see. There's a bug in locking. Will fix soon.

@lingol
Copy link
Collaborator

lingol commented Nov 30, 2018

Fixed with commit. Try it.

@BrotooLu
Copy link
Author

may the SCOPEDLOCK(m_sharedProcessLock) also be one step ahead to keep process safe?

@lingol
Copy link
Collaborator

lingol commented Nov 30, 2018

may the SCOPEDLOCK(m_sharedProcessLock) also be one step ahead to keep process safe?

NO, that would be unnecessary.

@BrotooLu
Copy link
Author

If not, get*** interface may use a dangerous MMBuffer which may be changed by other process.

@lingol
Copy link
Collaborator

lingol commented Nov 30, 2018

Think again. Is MMBuffer itself cross process, or the mmap file data?

@lingol
Copy link
Collaborator

lingol commented Nov 30, 2018

Fixed with v1.0.14.

@lingol
Copy link
Collaborator

lingol commented Nov 30, 2018

If not, get*** interface may use a dangerous MMBuffer which may be changed by other process.

Think again. Is MMBuffer itself cross process, or the mmap file data?

Or, you can just write some code to test that out. Talk is cheap anyway.

@lingol
Copy link
Collaborator

lingol commented Nov 30, 2018

Thanks for your feedback. It's really helpful.

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

No branches or pull requests

2 participants