Android v3.0.0 "setDocumentExpiration()" hangs when is used inside "inBatch()"

Instead of the direct deletion of documents we use a “trashbin” - specially marked documents with the expiration set. Essentially the Kotlin function is like this:

fun deleteDocuments(vararg docIds: String) {
	database?.inBatch(UnitOfWork {
		val now = Date().time
		docIds.forEach { docId ->
			val doc = database.getDocument(docId) ?: return@forEach
			val type = doc.getString("type")
			val mdoc = doc.toMutable()

			mdoc.setString("type", "TrashBinModel")
			mdoc.setString("actualType", type)
			mdoc.setLong("dateOfDeletion", now)

			database?.save(mdoc)
			database?.setDocumentExpiration(mdoc.id, Date(now + FIVE_DAYS))
		}
	}
}

It worked well in v2.8.6, but in v3.0.0 (com.couchbase.lite:couchbase-lite-android-ktx:3.0.0) the working thread hangs on a call to setDocumentExpiration() (in fact in an internal call to static native void setExpiration()). No exception is thrown. Since the transaction is not complete in any way the database is locked and cannot be used anymore.

While the transactional integrity in this particular case is not very important to us, it causes concerns about other places where inBatch() is used for multiple document modifications.

Yes. I totally believe that. I expect that there are quite a few database operations that will hang, if called from within a batch operation.

I think we could do a better job of documenting which operations are legal, from within a batch.

I’ve opened CBL-3135 to track the issue.

Thanks for catching this.