litedb-org / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.65k stars 1.25k forks source link

[BUG] Use EnterTransaction() before EnterLock(name) when update item #2463

Closed lanopk closed 7 months ago

lanopk commented 7 months ago

Version 5.0.19 / .net 6.0.28

Describe the bug Call insert/update/delete from several threads. Each call uses a lock, but find-related calls do not use a lock. Errors never occur when doing simple tasks, but errors always occur when processing a lot of tasks. The occurrence location is the EnterLock function in LockService.cs and occurs in the ENSURE section.

DB Update Error : LiteDB.LiteException: Use EnterTransaction() before EnterLock(name)
   at LiteDB.Engine.LockService.EnterLock(String collectionName)
   at LiteDB.Engine.Snapshot..ctor(LockMode mode, String collectionName, HeaderPage header, UInt32 transactionID, TransactionPages transPages, LockService locker, WalIndexService walIndex, DiskReader reader, DiskService disk, Boolean addIfNotExists)
   at LiteDB.Engine.TransactionService.CreateSnapshot(LockMode mode, String collection, Boolean addIfNotExists)
   at LiteDB.Engine.LiteEngine.<>c__DisplayClass27_0.<Update>b__0(TransactionService transaction)
   at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn)
   at LiteDB.LiteCollection`1.Update(T entity)

The problem does not occur in 5.0.16, but occurs whenI update (Nuget) to version 5.0.19.

If you need more debugging on my part, please let me know what I should do and I will debug it in more detail.

Thank you.

lanopk commented 7 months ago

This is a duplicate. I will leave a comment at https://github.com/mbdavid/LiteDB/issues/2442.