TLDR: If a user requests to delete all their data during a replication… I seem to be unable to stop the replication.
I set up my replication thus:
var target = new URLEndpoint(url);
var auth = new BasicAuthenticator(id, server_password);
var sync_config = new ReplicatorConfiguration(database, target)
{
ReplicatorType = ReplicatorType.PushAndPull,
Continuous = true,
Authenticator = auth
};
replicator = new Replicator(sync_config);
listenerToken = replicator.AddChangeListener(SyncStatusUpdate);
replicator.Start();
If there is a lot of data to replicate, the replication runs happily, and I get the notifications.
However, during that replication, if the user selects “delete all my local data”, I want to stop replication and then delete the database.
I do it like this:
log.Debug("Stopping sync agent");
// Check if syncing hasn't even started yet.
if (replicator == null)
return;
try
{
replicator.Stop();
replicator.RemoveChangeListener(listenerToken);
}
catch (Exception e)
{
log.Error(e, "Failed to stop sync agent");
// we need to keep going...
}
replicator = null;
I’m sure the exception is not being thrown - that is the stop seems to succeed.
I then wait a couple of seconds (elsewhere it was mentioned that things might take a couple of seconds to stop) before I start testing for the status == ReplicatorActivityLevel.Stopped. When this is true, I keep going. NOTE that I have extended this wait out to 20 seconds, but that doesn’t help.
Note that at this point, I am still receiving update events to my SyncStatusUpdate function. I shouldn’t be - but it is an indication that sync is not stopping.
Lastly I attempt to delete the database. I have tried Close then Delete, and Delete then Close. Both raise “please stop all replicators” errors. I have a “desperation” measure where I simply trash the files:
public void CloseAndDeleteDB()
{
try
{
database.Delete();
database.Close();
database = null;
}
catch (Exception e)
{
log.Error(e, "Failed to delete database!");
// Lets try another route - by deleting it
try
{
database.Close();
}
catch { }
database = null;
var dir = Path.Combine(path, config.DBName + ".cblite2");
Directory.Delete(dir, true);
}
database = null;
}
A little later I create a fresh new database with no data, and my application then hangs.
So the question is… what else do I need to do to ensure replication stops, even when it is in the middle of a large replication, potentially with a lot of images (few MB in size).
Thx.
Paul