This has been a bit of a rabbit hole but I’m none the wiser as of yet. Let’s go over what I found out one-by-one.
Logs
A NullPointerException
is thrown when running code similar to
if (document.contains("myKey")
Before running this code and before retrieving the document from the database I log the document ID like so:
FirebaseCrashlytics.getInstance().log("document ID = " + documentId);
After retrieving the document I log if it is null
FirebaseCrashlytics.getInstance().log("document == null " + (document == null ? "yes" : "no"));
Here’s a screenshot of the logs in Firebase Crashlytics:
The document that is retrieved from the database and then updated is always the same in the screenshot. Copy-pasting the document ID in Couchbase Server’s dashboards shows the document.
Repro
Not yet. I might have seen another issue - which may have resulted from the failed document update - on one of my devices though a few days ago.
As briefly as possible about the code path where the issue arises:
- one or more documents of type A are updated
- live query picks up the changes and some code updates a single document of type B. That document stores progress statistics. That is the document that isn’t found in the database.
If two devices are active at the same time it is possible that
- Device_1 updates documents of type A and syncs them
- Device_2 gets the changes and updates the statistics document
- Device_1 updates the statistics document
- Possible conflicts
I gathered those warnings:
2021-05-25 22:06:11.583 E/CouchbaseLite/REPLICATOR: {N8litecore4repl6PusherE#2} Got error response to rev 'my::doc::id' #155-05455665d517246cad29eadc6cdff324000cb088 (seq #1383): HTTP 409 'Document revision conflict'
2021-05-25 22:06:11.760 D/LOG: document == null no
2021-05-25 22:06:11.771 W/CouchbaseLite/DATABASE: Parallel executor overflow: 1
2021-05-25 22:06:11.802 W/System.err: CouchbaseLiteException{CouchbaseLite,10409,'Document revision conflict
2021-05-25 22:06:11.803 W/System.err: (CouchbaseLite Android v2.8.5-1 (CE/release, Commit/40e7b34008@c65a5127e818 Core/2.8.5 (1) at 2021-03-10T01:41:36.538Z) on Java; Android 10; Nokia 1 Plus)'}
2021-05-25 22:06:11.805 W/System.err: at com.couchbase.lite.internal.CBLStatus.toCouchbaseLiteException(CBLStatus.java:96)
2021-05-25 22:06:11.805 W/System.err: at com.couchbase.lite.internal.CBLStatus.toCouchbaseLiteException(CBLStatus.java:58)
2021-05-25 22:06:11.805 W/System.err: at com.couchbase.lite.internal.CBLStatus.convertC4Error(CBLStatus.java:38)
2021-05-25 22:06:11.805 W/System.err: at com.couchbase.lite.AbstractReplicator.documentEnded(AbstractReplicator.java:783)
2021-05-25 22:06:11.806 W/System.err: at com.couchbase.lite.AbstractReplicator$ReplicatorListener.lambda$documentEnded$1(AbstractReplicator.java:279)
2021-05-25 22:06:11.807 W/System.err: at com.couchbase.lite.-$$Lambda$AbstractReplicator$ReplicatorListener$AQbJ61Z6BP7-H2rKuYcxertPVV0.run(Unknown Source:6)
2021-05-25 22:06:11.807 W/System.err: at com.couchbase.lite.internal.AbstractExecutionService$InstrumentedTask.run(AbstractExecutionService.java:94)
2021-05-25 22:06:11.807 W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2021-05-25 22:06:11.808 W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2021-05-25 22:06:11.808 W/System.err: at java.lang.Thread.run(Thread.java:919)
As much as I tried I wasn’t able to force a “document == null yes” log. I’m planning to update the code and manually update the statistics document instead of observing changes and acting on them. This will make sure that a conflict won’t happen in this scenario.
Why 2.8.5
I assume that the issue was introduced after CBL 2.8.1 since the app code I described above hasn’t changed much in the last 2-3 years. The first app update released with 2.8.5 showed 97% of users didn’t run into a crash. App versions before that show nearly 100% crash-free users. The app update also included building for targetSdkVersion 30 (Android 11) from targetSdkVersion 29. The issue that a document retrieved from the database was not found was the most prominent crash and it appeared for the first time in this app version, too. Then I started logging the document ID. The issue persists, the document can be viewed in the dashboard of Couchbase Server and meta data doesn’t show that the document was deleted at some point in time.
Would it be safe to go back to 2.8.1? If the issue keeps popping up I’d know it’s not an issue with 2.8.5 at least.