realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

deadlock happens on specific device when using encryption example #1333

Closed tebica closed 8 years ago

tebica commented 8 years ago

one of Korean developer having deadlock issue when using Realm encryption example.

They tried our encryption example and Realm.getInstance() function never returned.

This happens only on LG G3 phone with LG G3(LG-F460S / OS: 4.4.2)

below is the only log that they can see when this issue happening

07-30 22:47:03.282 17838-18303/com.kakao.hello D/dalvikvm﹕ Trying to load lib /data/app-lib/com.kakao.hello-1/librealm-jni.so 0x43029850 
07-30 22:47:03.282 17838-18303/com.kakao.hello D/dalvikvm﹕ Added shared lib /data/app-lib/com.kakao.hello-1/librealm-jni.so 0x43029850
cmelchior commented 8 years ago

That does sounds a bit strange. Are there any form of device management software running on that device?

Also it could be interesting to see what happens if you could attach a debugger to see exactly where inside the Realm.getInstance() call it blocked.

beeender commented 8 years ago

Please try this: 1 Set a breakpoint on getInstance

2 Start debuging, when the debugpoint reached, find the pid of the app by:

adb shell ps | grep <app name>

3 Use strace to get more information by:

adb shell run-as <app's package name> strace -f -p <the pid got from step 2>

4 Continue running the app

5 After it get stalled, send the strace log in the terminal to us.

Thanks!

jungilhan commented 8 years ago

@cmelchior It's blocked at createNativeWithImplicitTransactions() method.

SharedGroup.java

57    public SharedGroup(String databaseFile, boolean enableImplicitTransactions, Durability durability, byte[] key) {
58        if (enableImplicitTransactions) {
59            nativeReplicationPtr = nativeCreateReplication(databaseFile, key);
60            nativePtr = createNativeWithImplicitTransactions(nativeReplicationPtr, durability.value, key);
61            implicitTransactionsEnabled = true;
62        } else {
63            nativePtr = nativeCreate(databaseFile, Durability.FULL.value, false, false, key);
64        }
65        context = new Context();
66        path = databaseFile;
67        checkNativePtrNotZero();
78    }

I have attached a screenshot. 2015-07-31 8 17 00

cmelchior commented 8 years ago

@jungilhan Do you know which version of the Android System WebView that is installed on the device? https://play.google.com/store/apps/details?id=com.google.android.webview&hl=en

It might seem completely unrelated, but they had an old bug that might effect this

jungilhan commented 8 years ago

@cmelchior Android System WebView is not installed on the device.

device-2015-07-31-210034

jungilhan commented 8 years ago

@beeender I have tried, But I can't see any trace output.

beeender commented 8 years ago

@jungilhan Can you please paste the output in the terminal from step 2 & 3 here?

jungilhan commented 8 years ago

@beeender I got message "run-as: exec failed for strace Error:Permission denied".

2015-07-31 9 40 33

beeender commented 8 years ago

@jungilhan That is strange... strace should not ask for root permission... Try strace with su if your phone is rooted.

Or, even simpler, open the app, wait there until ANR happens, then send the whole logcat to us. Then there should be a native backtrace in.

jungilhan commented 8 years ago

@beeender Hmmm... ANR dialog is not showing. Please see the attached video and log.

Another LG G3(LG-F460S / OS: 4.4.2) phone gives the same result.

cmelchior commented 8 years ago

I think you will only get an ANR if there is another event it cannot respond to, like if you touched the screen. Said said, that doesn't have any impact on why it is hanging. Thank you for trying with another phone as well.

Qubitium commented 8 years ago

Isolating the .so in question just to be extra paranoid. Remove all native libs from 0.82 jar except for armv7. This should confirm the phone is running on the correct .so and not the arm one.

jungilhan commented 8 years ago

@diegomontoya Could you explain to me how to remove so files from realm-0.82.0.jar?

emanuelez commented 8 years ago

Just rename the realm jar file extension to .zip, unzip it, remove the unwanted .so files, zip it again and rename it to .jar

jungilhan commented 8 years ago

@emanuelez I got build error below,

2015-08-04 10 24 36
emanuelez commented 8 years ago

That looks like Realm is not loaded at all. Can I see your build.gradle file ?

Qubitium commented 8 years ago

@jungilhan if on Windows, just use 7zip to right click open the jar file (open archive) and delete the libs/xxx folders you don't want.

tebica commented 8 years ago

@emanuelez @nhachicha , Here is the project file that he is using. https://dl.dropboxusercontent.com/u/539401/encryption%203.zip which has the build.gradle in it. Can you kindly check? app/libs/realm-0.82.0.jar -> has all .so app/libs/realm-0.82.0-strip.jar -> has v7a only

nhachicha commented 8 years ago

@tebica I had a friend testing the APK on a G2 LG-D802 & it works [ro.product.model]: [LG-D802] Is it working as well for the OP on a LG G2 ?

tebica commented 8 years ago

@nhachicha : It seems like issue happens only G3 specific model LG-F460S (Korea model) Not reproducible on G2. I have the specific model LG-F460S on my hand. What should be the next thing that I should check?

kneth commented 8 years ago

Adding io.realm.internal.Util.setDebugLevel(5) before the first call to any Realm method will give you a "trace" of the JNI calls. That might tell you where the deadlock is.

beeender commented 8 years ago

We got some useful information to debug this. Core team is working on it.

beeender commented 8 years ago

Fixed in 0.82.2 . Caused by the system's crypto function.