Skip to content

SQLiteAsyncConnection does not release database file #740

@gentledepp

Description

@gentledepp

Hi!

I made a PR to support storing guids as blobs #739

When running the tests, I noticed, that the async tests fail - except of the very first one.
The exception that causes the UTs to fail is

SetUp : System.IO.IOException : The process cannot access the file '......async.db' because it is being used by another process

Note, that I am running these tests with
USE_SQLITEPCL_RAW

it seems that everything is disposed correctly in the tests.
Then I found [this issue on stackoverflow] (https://stackoverflow.com/questions/8511901/system-data-sqlite-close-not-releasing-database-file) which sounded pretty similar.
Explanation:

What happens when you call SQLiteConnection.Close() is that (along with a number of checks and other things) the SQLiteConnectionHandle that points to the SQLite database instance is disposed. This is done through a call to SQLiteConnectionHandle.Dispose(), however this doesn't actually release the pointer until the CLR's Garbage Collector performs some garbage collection. Since SQLiteConnectionHandle overrides the CriticalHandle.ReleaseHandle() function to call sqlite3_close_interop() (through another function) this does not close the database.

So I tried out their solution, which is adding a call to "GC.Collect" in order to be able to delete the file.


        [SetUp]
    	public void SetUp()
    	{
    		SQLite.SQLiteConnectionPool.Shared.Reset ();
        #if NETFX_CORE
        //...
        #else
    		_connectionString = Path.Combine (Path.GetTempPath (), DatabaseName);
    		_path = _connectionString;
    		GC.Collect ();
    		GC.WaitForPendingFinalizers ();
    		System.IO.File.Delete (_path);
        #endif
    	}

This actually did the trick, however I am not sure in how to proceed...
@ericsink and @praeclarum:

  1. is this a known issue of SQLite.PCL.raw?
  2. Is it intended? If so, how do I fix it
  3. I tried to upgrade to SQLitePCLRaw v1.1.11 but that did not change anything

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions