Replicator refuses to stop during network outage, preventing CBLDatabase from closing

Using iOS Objective-C CBL v2.8.4 – App opens a local CBLDatabase, then starts it replicating. Replication then idles, having sync’d all documents. At this point, the network goes down and the app attempts to stop the replication by calling CBLReplicator’s -stop method and removing the listener token it had acquired earlier. Instead of stopping cleanly, the replication appears to stop (cf. CBL logs) but doesn’t end up calling -stopped method. It then continues with retries until it runs out of attempts (i.e. basically forever). App then calls CBLDatabase -close: method, this method hangs by spinning forever on _closeCondition because activeStoppables is never emptied out because the CBLReplicator’s -stopped method is never called.

Is there a way to short circuit this behaviour and force the replication to stop?

if you want to limit the retry count, you can set that up in replicator config maxAttempts()

retry config

For the replication stop not happening when network is down issue, could you share complete logs during the session in a gist or texfile, I can go through them.

Happy to do so. Here’s the gist of the entire debug log level output. I’ve annotated it in the crucial spots.

Sadly, the maxAttempts property is not available on the v2.8.4 CBL library I’m using. In any case, I would need to lower it on the fly rather than set it at replicator initialization.

I’ve done some further testing. The problem appears to show up in the simulator only (simulator is running iOS 14.4). On real devices I cannot reproduce.

Current theory is that the flakiness of Reachability running under the simulator might be the problem.

We have fixed the replicator not getting stop when a transient error happens during the stop in 3.0.0. I understand that this the issue you are encountering is likely to be the same (e.g. the replicator keeps retrying after stop). Could you update to use the latest version (3.0.1) and see if the issue is resolved?