couchbase / couchbase-lite-java-ce-root

The root workspace for the Community Editions of the Java language family of products (Java Desktop, Java WebService, and Android)
Other
51 stars 13 forks source link

"Cannot start a transaction within a transaction" error when trying to access expired document #16

Closed juho-ylikyla closed 3 years ago

juho-ylikyla commented 3 years ago

When a document has an expiration date, sometimes when attempting to read an expired document on android application startup, we get the following error:

java.lang.Error: LiteCoreException{domain=3, code=1, msg=cannot start a transaction within a transaction}
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1173)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: LiteCoreException{domain=3, code=1, msg=cannot start a transaction within a transaction}
at com.couchbase.lite.internal.core.C4Database.purgeExpiredDocs(Native Method)
at com.couchbase.lite.internal.core.C4Database.purgeExpiredDocs(C4Database.java:103)
at com.couchbase.lite.DocumentExpirationStrategy.purgeExpiredDocuments(DocumentExpirationStrategy.java:85)
at com.couchbase.lite.DocumentExpirationStrategy.lambda$W1d7EnxL3_HToVEg8jqb-tAaQZg(Unknown Source:0)
at com.couchbase.lite.-$$Lambda$DocumentExpirationStrategy$W1d7EnxL3_HToVEg8jqb-tAaQZg.run(Unknown Source:2)
at com.couchbase.lite.internal.AbstractExecutionService$InstrumentedTask.run(AbstractExecutionService.java:94)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
... 2 more

How to reproduce

  1. Set an expiration date to a document in couchbase to some point in the future. databaseInstance.setDocumentExpiration(mutableDoc.getId(), expirationDate);

  2. Close the app, wait until the document should expire.

  3. Open the app and immediately after the database instance has been created, read the contents of the document

    Database databaseInstance = new Database(name, configuration);
    Document documentFromDb = databaseInstance.getDocument(documentId);
  4. Sometimes the app crashes with the above stack trace

Expected behaviour

The getDocument call should not throw an exception but return a null

Couchbase version: 2.7.1

bmeike commented 3 years ago

I have not been able to reproduce this.

juho-ylikyla commented 3 years ago

I'll upgrade and report back what happens. Unfortunately, we have to test run this in production to get the data since this happens only with certain devices. 😅

I have been able to reproduce this only with the release app bundle, not with an debug apk. This is not reproducible with unit tests for example.

juho-ylikyla commented 3 years ago

Upgrading to 2.8.5 fixed the issue, thank you for the support!