[BUG] currupt or damaged records version 5.0.5 and newer
See original GitHub issueVersion Running on linux docker using master version up to commit below as i needed one of the othere fixes. https://github.com/mbdavid/LiteDB/commit/96e4ee71c0250e1349d13e86730e5d62319f715d
Describe the bug When the database is used i am finding that some of my records are getting damaged. It seems to relate to fields of type Dictionary<string,guid> on the class i am saving but a standard unit test can’t duplicate. Further details on the question i opened (https://github.com/mbdavid/LiteDB/issues/1600). I started debugging the read since i can’t easily duplicate the write issue in a dev environment and it looks like a records gets over ridden by another or something strange like a byte being wrong causing things to get mixed up.
Code to Reproduce Use the attached database and the code below damaged database.zip
using (var db = new LiteDatabase(@"O:\drive issues\VirtualFileSystem_litedb_stuffed.db"))
{
var col = db.GetCollection<VirtualDirectory>("directories");
var dir = col.FindById(Guid.Parse("3e70872d-30cf-47f9-b360-782b034b6b95"));
}
public class VirtualDirectory
{
public Guid Id { get; set; }
public ulong Size { get; set; }
public uint RefCount { get; set; }
public ushort Permission { get; set; }
public DateTime ATime { get; set; }
public DateTime MTime { get; set; }
public DateTime CTime { get; set; }
//info about dir ref count being 2 for empty directory
//https://unix.stackexchange.com/a/153640
public Dictionary<string, Guid> Files { get; set; } = new Dictionary<string, Guid>();
public Dictionary<string, Guid> Directories { get; set; } = new Dictionary<string, Guid>();
internal VirtualDirectory()
{
}
}
Expected behavior The instance of the class should be returned correctly from the database
Screenshots/Stacktrace System.NotSupportedException: BSON type not supported at LiteDB.Engine.BufferReader.ReadElement(HashSet`1 remaining, String& name)
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13
Top GitHub Comments
@lbnascimento i spoke too soon. seems i was not catching all exceptions. Sadly i think i need to look at another DB for now as i keep hitting too many bugs in LiteDb and i am spending more time trying to find them code around them than my actual application. The project is great but there real needs to be a clear difference between the stable releases and the beta ones and really get the fixes released a little faster for testing for bad releases like the latest one was.
Having the same issue since I’ve upgraded to v5. Similarly to the OP, it seems to be related to a Dictionary<string, BsonDocument> property (in C# it’s a Dictionary<ulong, class>, but the ulong seems to get serialized as a plain string). I suspect this, because it only happens to this specific collection.
Some of the documents in this collection are getting randomly corrupted, which prevents them from deserializing. This happens to a few specific documents, while all the other documents in the collection can be deserialized just fine (despite also having data in the dictionary). I can export the document to JSON, fix it manually and Upsert it back into the collection. It works fine for a few minutes, but then it gets corrupted again. Same as OP, this is a multithreaded program.