__next_prime overflow exception

Hello,
when I’m using couchbase lite (free version), after some time, ANY cache query start throwing __next_prime overflow exception.
for example:

  • when I create N1QL:
    database.createQuery(query)
    I get exception
[cache] Error : com.couchbase.lite.CouchbaseLiteException: __next_prime overflow
 (CouchbaseLite Android v3.0.5-1@31 (CE/release, Commit/unofficial@3e782b88ecec Core/3.0.5 (1) 
at 2022-10-19T18:22:13.132643Z) on Java; Android 12; M2101K9G)
at com.couchbase.lite.N1qlQuery.prepQueryLocked(N1qlQuery.java:54)
at com.couchbase.lite.AbstractQuery.getC4QueryLocked(AbstractQuery.java:206)
at com.couchbase.lite.AbstractQuery.getC4Query(AbstractQuery.java:186)
at com.couchbase.lite.N1qlQuery.compile(N1qlQuery.java:57)
at com.couchbase.lite.AbstractDatabase.createQuery(AbstractDatabase.java:656)
at com.couchbase.lite.Database.createQuery(Database.java:30)
...
  • Another situation using query builder, on query.execute()
 Query query = .....
ResultSet resultSet = query.execute();
[DefaultDispatcher-worker-1] Error : com.couchbase.lite.CouchbaseLiteException: __next_prime overflow
(CouchbaseLite Android v3.0.5-1@31 (CE/release, Commit/unofficial@3e782b88ecec Core/3.0.5 (1)
 at 2022-10-19T18:22:13.132643Z) on Java; Android 12; M2101K9G)
at com.couchbase.lite.BuilderQuery.prepQueryLocked(BuilderQuery.java:83)
at com.couchbase.lite.AbstractQuery.getC4QueryLocked(AbstractQuery.java:206)
at com.couchbase.lite.AbstractQuery.execute(AbstractQuery.java:101)
at com.couchbase.lite.Where.execute(Where.java:30)
...

Info:

  • Phone: xiaomi mi 11 lite
  • System : Andriod 12
  • Lib: com.couchbase.lite:couchbase-lite-android:3.0.5
  • I’m using kotlin coroutines to make async queries

Is the app also crashed? and Is there a tombstone file? Basically, I’m trying to see if we could get more info about what is causing the overflow error.

Also does the issue happen only on a specific query? Can this issue be reproduced on an emulator? Can this issue be reproduced by running the same query in a loop for some time? Basically, we need something that we can use to reproduce the issue.

If you have access to the device on which the error occurs, you may be able to pull the tombstone files with the adb command:

adb bugreport

I’m not sure if this helps this case - but here’s a stackoverflow issue for that exception with a possible solution : c++ - __next_prime symbol undefined - Stack Overflow

It’s hard to reproduce this error. I think the reason is making a lot of queries in short frame of time.
This error occured only once per few days, to fix this issue I created method to catch the exception, reopen the database (close db-> open db) and replay the queries.

@pasin I did not test it on emulator, but my friends also had this error while testing application on thier phones (samsung s22, huawei)

I’m sort of guessing that this is a similar situation to “lack of entropy”. If you query /dev/urandom fast enough you will run out of entropy and need to wait for a moment while it gets more. The message here kind of suggests that the phone is running out of prime numbers and needs to calculate more. I don’t know what would be using those here (it is not us) but I don’t think there is a good workaround other than what you’ve done, or to throttle your queries.