C# iOS - Cannot delete database

I am trying to close, delete, and replace a database. iOS (only - Android and UWP work with same code) gives me a file in use message when I try to overwrite a database file even after closing it. I have stopped, and disposed the replicator and closed the database. The logs below seem to indicate that everything is closed successfully. Any thoughts?

2020-08-26 18:18:13.564573-0400 Redbook.Mobile.iOS[10049:573175] [53]| INFO) [Replicator] (WebSocketWrapper) [53] Closing socket normally due to request from LiteCore
Thread finished: #512020-08-26 18:18:13.565059-0400 Redbook.Mobile.iOS[10049:573175] [53]| INFO) [Network] {C4SocketImpl#13} Socket disconnected cleanly
2020-08-26 18:18:13.565337-0400 Redbook.Mobile.iOS[10049:573175] [53]| INFO) [Network] {C4SocketImpl#13} sent 268 bytes, rcvd 97, in 1.836 sec (146/sec, 53/sec)

2020-08-26 18:18:13.568847-0400 Redbook.Mobile.iOS[10049:573064] [14]| INFO) [Network] {Connection#9} Closed with WebSocket status 1000:
2020-08-26 18:18:13.569173-0400 Redbook.Mobile.iOS[10049:573070] [18]| INFO) [Replicator] {Repl#11} Connection closed with WebSocket status 1000: “” (state=3)
2020-08-26 18:18:13.569561-0400 Redbook.Mobile.iOS[10049:573064] [14]| INFO) [Replicator] {Puller#18} activityLevel=stopped: pendingResponseCount=0, _caughtUp=0, _pendingRevMessages=0, _activeIncomingRevs=0
2020-08-26 18:18:13.569935-0400 Redbook.Mobile.iOS[10049:573070] [18]| INFO) [Replicator] {Repl#11} activityLevel=busy: connectionState=0
2020-08-26 18:18:13.570293-0400 Redbook.Mobile.iOS[10049:573064] [14]| VERBOSE) [Replicator] {Puller#18} now stopped
2020-08-26 18:18:13.570907-0400 Redbook.Mobile.iOS[10049:573070] [18]| INFO) [Replicator] {Repl#11} pushStatus=stopped, pullStatus=stopped, progress=0/0
2020-08-26 18:18:13.571263-0400 Redbook.Mobile.iOS[10049:573070] [18]| INFO) [Replicator] {Repl#11} activityLevel=stopped: connectionState=0
2020-08-26 18:18:13.571703-0400 Redbook.Mobile.iOS[10049:573070] [18]| INFO) [Replicator] {Repl#11} now stopped
2020-08-26 18:18:13.572075-0400 Redbook.Mobile.iOS[10049:573070] [18]| INFO) [Replicator] BLIP sent 2 msgs (246 bytes), rcvd 0 msgs (89 bytes) in 1.843 sec. Max outbox depth was 1, avg 1.00Thread finished: #50

2020-08-26 18:18:13.575036-0400 Redbook.Mobile.iOS[10049:573070] [18]| VERBOSE) [Database] {DB#7} Pre-close housekeeping: 0 of 19840 pages free (0%)
2020-08-26 18:18:13.575978-0400 Redbook.Mobile.iOS[10049:573070] [18]| VERBOSE) [Database] {DB#7} Closed SQLite database
2020-08-26 18:18:13.576296-0400 Redbook.Mobile.iOS[10049:573070] [18]| INFO) [Database] {DB#7} Closing database
2020-08-26 18:18:13.664690-0400 Redbook.Mobile.iOS[10049:573058] [Thread Pool Worker]| VERBOSE) [Database] {DB#3} begin transaction
2020-08-26 18:18:13.665051-0400 Redbook.Mobile.iOS[10049:573078] [Thread Pool Worker]| VERBOSE) [Database] {DB#6} begin transaction
2020-08-26 18:18:13.666889-0400 Redbook.Mobile.iOS[10049:573058] [Thread Pool Worker]| VERBOSE) [Database] {DB#3} abort transaction
2020-08-26 18:18:13.667549-0400 Redbook.Mobile.iOS[10049:573078] [Thread Pool Worker]| VERBOSE) [Database] {DB#6} abort transaction
2020-08-26 18:18:13.669593-0400 Redbook.Mobile.iOS[10049:573078] [Thread Pool Worker]| INFO) [Database] (Database) [Thread Pool Worker (11)] DB[/Users/brian/Library/Developer/CoreSimulator/Devices/88377BDC-6E4D-4DF2-87F8-591857908790/data/Containers/Data/Application/57ABBEE2-32AB-47CE-BA74-1D5BCA687708/Library/ebook/RedbookLog.cblite2/] purged 0 expired documents
2020-08-26 18:18:13.669844-0400 Redbook.Mobile.iOS[10049:573058] [Thread Pool Worker]| INFO) [Database] (Database) [Thread Pool Worker (6)] DB[/Users/brian/Library/Developer/CoreSimulator/Devices/88377BDC-6E4D-4DF2-87F8-591857908790/data/Containers/Data/Application/57ABBEE2-32AB-47CE-BA74-1D5BCA687708/Library/ebook/RedbookCore.cblite2/] purged 0 expired documents
2020-08-26 18:18:13.671249-0400 Redbook.Mobile.iOS[10049:573058] [Thread Pool Worker]| VERBOSE) [Database] {DB#3} Next expiration time is 0
2020-08-26 18:18:13.671671-0400 Redbook.Mobile.iOS[10049:573058] [Thread Pool Worker]| INFO) [Database] (Database) [Thread Pool Worker (6)] No pending doc expirations
2020-08-26 18:18:13.672223-0400 Redbook.Mobile.iOS[10049:573078] [Thread Pool Worker]| VERBOSE) [Database] {DB#6} Next expiration time is 0
2020-08-26 18:18:13.672917-0400 Redbook.Mobile.iOS[10049:573078] [Thread Pool Worker]| INFO) [Database] (Database) [Thread Pool Worker (11)] No pending doc expirations
2020-08-26 18:18:18.630965-0400 Redbook.Mobile.iOS[10049:572981] Xamarin.iOS: Processing: ‘exit process’

To delete a database, call Database.delete … don’t try to overwrite it yourself.
I don’t see any error messages in the log above, so I don’t know what you were doing or what went wrong.

@jens, thanks - I am using that call. Upon further investigation, I’ve managed to change my message and it now states that the database cannot be closed until all replicators have stopped. I have one and only one replicator and I have called Stop() on it. But I know that doesn’t really stop it, so what can I do here? I really need to force the replicator to shut down within a second or less so that I can move on and close / delete the database. Or will a single call to Delete() handle all of that for me?

You need to wait for the replicator’s listener to be told that the replicator has stopped.

There have been issues in the past with replicators not stopping quickly — for example if it lost contact with the server, or if it was waiting for the TCP connection to start up. That should be fixed in 2.7.

Not in current release. Stay tuned for enhancements on this front in our upcoming release

In meantime, as Jens mentioned, 2.7 has enhancements that will force close open replicators if it does not gracefully close within a specified time (roughly 5 seconds )- wait for 20 sec or so after issuing the replicator close and then attempt to close the database.

Thanks @priya.rajagopal. Any idea when 2.7 will be released?

2.7 has been out since Jan.

Right. And I just checked and I’m using 2.7.1, so why are my replicators still remaining open for many seconds after I close them? I can see up to 5, but they just keep running as though they have ignored my call to close.

Turn on replication logging and collect the logs covering the time from just before you tried to stop the replicator. That’s going to be large, so it’s best to file an issue on Github against CBL .NET and put the logs in a file attachment or a gist.

You may want to check out 2.8 release out last week …delete() should take care of closing all open replicators…