Litedb: [BUG] Release 5.0.5 is bad - multiple issues with code working on past version

Created on 27 Mar 2020  路  6Comments  路  Source: mbdavid/LiteDB

Version
LiteDB 5.0.5 on dotnet core 3.1 windows and linux

Describe the bug
null pointers coming from multi different actions inside LiteDB on code thar was working on version 5.0.4. (was having an issue with records not been found sometimes but i think that relates to bug someelse reported)

Code to Reproduce
putting lines from my code so may not be perfect but should give rough idea.
```C#
_db = new LiteDatabase( "MappingAndWriteCache.db");
_mappings = _db.GetCollection();
_mappings.EnsureIndex("Status", record => record.Status);
_mappings.EnsureIndex("DataSourceFileId", record => record.DataSourceFileId);
_mappings.EnsureIndex("FileId", record => record.FileId);
_mappings.Upsert(new MappingRecord
{
Id = id,
FileId = fileId,
BlockNbr = blockNbr,
DataSourceFileId = null,
DataSourceFileBlockOffset = 0,
DataSourceFileBlockLength = block.Length,
LastModified = DateTime.UtcNow,
Status = BlockStatus.New
});

public enum BlockStatus { New, BatchedForUpload, Uploaded, Empty }

public class MappingRecord
{
public string Id { get; set; }
public string FileId { get; set; }
public uint BlockNbr { get; set; }
public string DataSourceFileId { get; set; }
public long DataSourceFileBlockOffset { get; set; }
public int DataSourceFileBlockLength { get; set; }
public DateTime LastModified { get; set; }
public BlockStatus Status { get; set; }
}


**Expected behavior**
Upsert should happen without null pointer below.

**Screenshots/Stacktrace**

System.NullReferenceException: Object reference not set to an instance of an object.
at LiteDB.BsonValue.GetHashCode()
at System.Linq.Set1.InternalGetHashCode(TElement value) at System.Linq.Set1.Add(TElement value)
at System.Linq.Enumerable.DistinctIterator1.MoveNext() at LiteDB.Engine.LiteEngine.InsertDocument(Snapshot snapshot, BsonDocument doc, BsonAutoId autoId, IndexService indexer, DataService data) at LiteDB.Engine.LiteEngine.<>c__DisplayClass30_0.<Upsert>b__0(TransactionService transaction) at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func2 fn)
at LiteDB.Engine.LiteEngine.Upsert(String collection, IEnumerable1 docs, BsonAutoId autoId) at LiteDB.LiteCollection1.Upsert(IEnumerable1 entities) at LiteDB.LiteCollection1.Upsert(T entity)
```
Additional context
This is the easiest one to isolate but basically all my unit tests over code using litedb is now failing with a lot of null pointers from different calls.

bug

Most helpful comment

This issue is already fixed in master and its fix will be present in the next incremental release.

All 6 comments

here is another example for one with on an insert instead

System.NullReferenceException: Object reference not set to an instance of an object.
   at LiteDB.BsonValue.GetHashCode()
   at System.Linq.Set`1.InternalGetHashCode(TElement value)
   at System.Linq.Set`1.Add(TElement value)
   at System.Linq.Enumerable.DistinctIterator`1.MoveNext()
   at LiteDB.Engine.LiteEngine.InsertDocument(Snapshot snapshot, BsonDocument doc, BsonAutoId autoId, IndexService indexer, DataService data)
   at LiteDB.Engine.LiteEngine.<>c__DisplayClass7_0.<Insert>b__0(TransactionService transaction)
   at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn)
   at LiteDB.Engine.LiteEngine.Insert(String collection, IEnumerable`1 docs, BsonAutoId autoId)
   at LiteDB.LiteCollection`1.Insert(T entity)

this second case is in a transaction shown below and happens on the commit so i can't tell which of the 2 inserts caused it.

C# if (!_db.BeginTrans()) { //failed to get transaction //could not get transaction so fail throw new Exception("could not create transaction"); } try { var dirId = _directoriessCollection.Insert(new VirtualDirectory() { CTime = DateTime.Now, ATime = DateTime.Now, MTime = DateTime.Now, Permission = 0b111_111_111,// rwx_rwx_rwx RefCount = 2, //references it selft and parent references it Size = 0 }).AsGuid; _pathsCollection.Insert(new VirtualPath() { Id = rootPath, Directory = dirId }); _db.Commit(); }

@seertenedos I found the bug regarding your first example and commited a fix to master. I couldn't reproduce the error in your second example (not even without the fix), but since it seems to be the same error, it probably happened in a property in VirtualPath that was not attributed a value and for which existed an index.

Great. You should enable a prerelease that always points to the latest master. Then people like myself can test fixes etc and some people may run or test versions before release. I would love to test this fix and the other fix in 5.0.5 to see if it fixes some strangeness i have with records coming back on a find on the first call but not the second right after each other in a transaction for the same record some times.

@lbnascimento i copied the latest master srouce code into my application and i am happy to say that seems to have fixed my bugs from the release and the bug fix in the release itself also fixed the other bug i have been trying to track down in the database. Can't wait for the release.

Got the same issues, reverted to 5.0.4 and it is working without code change.

This issue is already fixed in master and its fix will be present in the next incremental release.

Was this page helpful?
0 / 5 - 0 ratings