LiteDB
LiteDB copied to clipboard
[BUG] Cannot dispose DB after (expected) read only errors
Tested version: LiteDB 5.0.12
Steps to reproduce
- Open a database in read only mode.
- Invoke some
Insert. It fails as expected. - Dispose the database instance. This throws an unexpected exception.
- and the database file remains in use, e.g. cannot be deleted
Use the attached XUnit test project, ready to test. See code comments for the details.
From the attached test
// create the database, add a document
{
using (var db = new LiteDatabase(dbPath))
{
var c1 = db.GetCollection<Data>("c1");
c1.Insert(new Data { Id = 1, Name = "n1" });
}
}
// open the database read only and try to insert
{
var db = new LiteDatabase($"Filename={dbPath}; ReadOnly=true");
var c1 = db.GetCollection<Data>("c1");
// this exception is expected due to ReadOnly=true
// but the message is somewhat not clear
var ex1 = Assert.Throws<Exception>(() =>
{
c1.Insert(new Data { Id = 2, Name = "n2" });
});
Assert.Equal("LiteDB ENSURE: discarded page must be writable", ex1.Message);
// this exception is NOT EXPECTED, we are just closing the database
var ex2 = Assert.Throws<Exception>(() =>
{
db.Dispose();
});
Assert.Equal("LiteDB ENSURE: discarded page must be writable", ex2.Message);
// this exception is NOT EXPECTED, we should have closed the database and can delete the file
var ex3 = Assert.Throws<IOException>(() =>
{
File.Delete(dbPath);
});
Assert.StartsWith("The process cannot access the file", ex3.Message);
}
was this bug fixed?