realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

ThrowingException 16, std::exception in io_realm_internal_TableQuery.cpp line 1288

Open hohnamkung opened this issue 10 years ago • 26 comments

After ThrowingException 16, std::exception in io_realm_internal_TableQuery.cpp line 1288 exception is logged, i can't

  1. load data using Observable (Observable' s onNext not called, only ThrowingException 16, std::exception in io_realm_internal_TableQuery.cpp line 1288 is logged in logcat)
  2. load data synchronously (Requested table is not in this Realm. Creating it requires a transaction exception happens)
  3. insert data. Whenever i insert data, A RealmObject with no @PrimaryKey cannot be updated error happened, although that class has a @PrimaryKey annotated field.
  4. finally initialize Realm with ArrayIndexOutOfBoundsException: columnIndex > available columns.exception

Case 1~3 dismiss after process is restarted (swipe it in recent tasks), but i could reproduce below steps. After case 4, i uninstalled application and no longer reproduce any of problems.

Steps & Code to Reproduce

The class that have this problem query data and is listening changes (using observable) in main thread. At the same time every data about that class are removed (realm.delete(*.class)) and re-inserted with fresh one from server in worker thread.

I tried to find reproduce step for 1~2 hours, but i couldn't.

Version of Realm and tooling

Realm version(s): 1.0.0

Android Studio version: 2.1.1

Which Android version and device: 6.0.1 (Galaxy S6)

hohnamkung avatar May 30 '16 08:05 hohnamkung

Hello @hohnamkung

Thanks for the detailed description of the symptom. Is there anyway we could ask a simple sample to reproduce the problem you are going through? We could be more than happy to accelerate solving the issue once there is a tangible specimen available. We will strongly look forward.

stk1m1 avatar May 30 '16 08:05 stk1m1

Already i made a effort to find a way to reproduce it, but i couldn't find any. 😞 After case 1~3, i thought i can reproduce it so i uninstall application without backup realm file.

I'm not sure i can find a step to reproduce it or make a sample application. But i and my team members have this issues time to time, so i'll share a realm file if i run into it.

hohnamkung avatar May 30 '16 09:05 hohnamkung

@hohnamkung

~~We understand that the issue happens rarely. It really doesn't matter whether the issue could be 100% reproducible or not. We are looking forward to have a ground at least where we could collect sample data with an actual case of crash.~~

We'll investigate the issue according the scenario you've provided. Thanks for letting us know. 👍

stk1m1 avatar May 30 '16 10:05 stk1m1

Hi @stk1m1 I shared a sample project (still not reproducible) and some other founding to [email protected] Please check that out.

hohnamkung avatar Jun 02 '16 06:06 hohnamkung

D/REALM: jni: ThrowingException 16, std::exception in io_realm_internal_TableQuery.cpp line 1253, .
D/REALM: Exception has been throw: std::exception in io_realm_internal_TableQuery.cpp line 1253
W/System.err: java.lang.IllegalArgumentException: A RealmObject with no @PrimaryKey cannot be updated: class kr.co.vcnc.android.couple.between.api.model.anniversary.RAnniversary
W/System.err:     at io.realm.Realm.checkHasPrimaryKey(Realm.java:1178)
W/System.err:     at io.realm.Realm.copyToRealmOrUpdate(Realm.java:754)
W/System.err:     at kr.co.vcnc.android.couple.realm.RealmRunnable.lambda$transaction$1899(RealmRunnable.java:76)
W/System.err:     at kr.co.vcnc.android.couple.realm.RealmRunnable.access$lambda$3(RealmRunnable.java:0)
W/System.err:     at kr.co.vcnc.android.couple.realm.RealmRunnable$$Lambda$4.run(Unknown Source)
W/System.err:     at kr.co.vcnc.android.couple.realm.RealmRunnable.transaction(RealmRunnable.java:93)
W/System.err:     at kr.co.vcnc.android.couple.realm.RealmRunnable.transaction(RealmRunnable.java:75)
D/REALM: jni: ThrowingException 16, std::exception in io_realm_internal_TableQuery.cpp line 1288, .
D/REALM: Exception has been throw: std::exception in io_realm_internal_TableQuery.cpp line 1288
D/REALM: jni: ThrowingException 16, std::exception in io_realm_internal_TableQuery.cpp line 1253, .

hohnamkung avatar Jun 02 '16 06:06 hohnamkung

@hohnamkung

Thank you very much for your contribution! We'll keep investigating and reach you back.

stk1m1 avatar Jun 02 '16 06:06 stk1m1

Hi @hohnamkung Most of the errors seem to indicate schema changes somehow. Looking at the example you sent, you are copying an Realm file from assets, correct? Are you manipulating the file itself or the schema any other places?

cmelchior avatar Jun 02 '16 19:06 cmelchior

Yes, The realm file in example's asset folder was copied from problem reproducing device. (when exception happens) No i don't change anything in attached file. (just pull from device and push it into asset folder)

hohnamkung avatar Jun 03 '16 03:06 hohnamkung

Hi @hohnamkung I think we have identified an interaction between asynchronous listeners and synchronous RealmResults that could result in errors. Some of these errors will be solved by https://github.com/realm/realm-java/pull/2926, but we discovered it did not cover all corner cases.

However these errors should not result in some of error messages you are seeing, e.g Requested table is not in this Realm. Creating it requires a transaction still indicate that a Realm file with a wrong schema is being accessed.

cmelchior avatar Jun 06 '16 13:06 cmelchior

Thanks @cmelchior If i run into Requested table is not in this Realm. Creating it requires a transaction again, i'll get a some information and share it.

hohnamkung avatar Jun 07 '16 09:06 hohnamkung

Yes, thank you. Any info you have on that one will be highly appreciated.

cmelchior avatar Jun 07 '16 09:06 cmelchior

Since we haven't seen any more reports on this issue, I will either assume it has been fixed or was caused by something outside our control. Closing

cmelchior avatar Jan 24 '17 10:01 cmelchior

Crazy timing: after 7 months of no activity on this issue, i come across it today as I'm seeing it in my codebase, only to find it closed 2 hours ago.

Shall I create a new ticket with what details I can offer?

CDRussell avatar Jan 24 '17 12:01 CDRussell

@CDRussell No, i'll re-open this instead. Please provide as many details you can

cmelchior avatar Jan 24 '17 12:01 cmelchior

Same log statements as OP was seeing:

D/REALM: jni: ThrowingException 16, std::exception in io_realm_internal_TableQuery.cpp line 1282 D/REALM: Exception has been throw: std::exception in io_realm_internal_TableQuery.cpp line 1282

In my case, I have a huge amount of entries I'm downloading from our own server and trying to persist. Somewhere in the 18,000 region. I'm downloading each and persisting to Realm. (This is basically stress testing the capabilities of the app)

Most of them are persisting just fine, however, I'm occasionally seeing those logs happening. There is a lot of concurrency going on in my project, so a lot of threads will be each grabbing their own Realm reference, writing to the DB, and then closing the reference. Memory is also getting squeezed heavily when the sync is happening.

Given the vast number of records, it isn't clear if the data is failing to save when that happens or not.

Given that's all I see in the logs, I'm not sure what more data I can retrieve. Can I pull additional realm logs somehow?

Using Realm version:

classpath "io.realm:realm-gradle-plugin:1.2.0"

CDRussell avatar Jan 24 '17 12:01 CDRussell

Is it something you can reproduce somewhat reliably? Have you tried updating to 2.3?

Regarding logs In 2.* you can set the log level using RealmLog.setLogLevel(LogLevel.ALL) , in 1.2 I believe you need to do RealmLog.add(new AndroidLogger(LogLevel.TRACE)) instead.

cmelchior avatar Jan 24 '17 12:01 cmelchior

I can reproduce easily enough; it definitely happens many times over the course of one whole sync of that data.

I haven't tried upgrading to 2.3 yet. I can attempt that though I'm not sure how big a change footprint that'll have on the project. Will investigate how quickly I could test this.

I thought it was maybe each save attempt that was affected, but I just moved to another screen in my app and it died with this stacktrace

FATAL EXCEPTION: main Process: com.REDACTED, PID: 3119 java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1128 at io.realm.RealmQuery$5.call(RealmQuery.java:2161) at io.realm.RealmQuery$5.call(RealmQuery.java:2131) at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36) at java.util.concurrent.FutureTask.run(FutureTask.java:237) 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) Caused by: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1128 at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method) at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:445) at io.realm.RealmQuery$5.call(RealmQuery.java:2143) at io.realm.RealmQuery$5.call(RealmQuery.java:2131)  at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)  at java.util.concurrent.FutureTask.run(FutureTask.java:237)  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) 

And some more in the logs:

D/REALM: jni: ThrowingException 11, mmap() failed: Out of memory size: 134217728 offset: 1207959552 in io_realm_internal_SharedGroup.cpp line 188, . D/REALM: Exception has been throw: Unrecoverable error. mmap() failed: Out of memory size: 134217728 offset: 1207959552 in io_realm_internal_SharedGroup.cpp line 188

Out of memory could be the overall culprit perhaps?

CDRussell avatar Jan 24 '17 12:01 CDRussell

Out of memory should crash the app outright. Are you catching Errors somewhere?

Regarding upgrading. The list of breaking changes is here: https://github.com/realm/realm-java/blob/master/CHANGELOG.md#breaking-changes-1

cmelchior avatar Jan 24 '17 12:01 cmelchior

Not deliberately; though there's RxJava in the mix, which certainly could be masking an error somewhere.

CDRussell avatar Jan 24 '17 12:01 CDRussell

Upgraded to 2.3 - Still seeing the errors.

E/REALM_JNI: jni: ThrowingException 7, std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1297 E/REALM_JNI: Exception has been throw: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1297

CDRussell avatar Jan 24 '17 13:01 CDRussell