mbdavid / LiteDB

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

[BUG]Maximum number of transactions reached in 5.0.18, but 5.0.13 #2444

Closed mirror222 closed 3 months ago

mirror222 commented 3 months ago

LiteDB : 5.0.18 Windows 11 x64

I ran a simple test with the following code and found that the latest version (5.0.18) throws a "Maximum number of transactions reached" error, but the older version 5.0.13 does not.


using LiteDB;

namespace ConsoleApp1
{
    class Program
    {
        internal class MyKeyValue
        {
            [BsonId]
            public int Id { get; set; } 
            public string? Key { get; set; }   
            public BsonValue? Value { get; set; } 
        }

        private static void Main(string[] args)
        {
            using (var db = new LiteDatabase(new ConnectionString(":memory:")))
            {
                var _kvs = db.GetCollection<MyKeyValue>();
                var tasks = new List<Task>();

                for (int i = 0; i < 150; i++)
                {
                    var tmp = i;

                    tasks.Add(Task.Run(() =>
                     {
                         var item = new MyKeyValue()
                         {
                             Key = "KEY" + tmp,
                             Value = tmp,
                         };

                         var w = _kvs.Insert(item) > 0;
                         var r = _kvs.FindOne(x => x.Key == "KEY" + tmp);   //throw error  HERE

                         Console.WriteLine($"{tmp} {w} {r.Value}");
                     }));
                }

                Task.WaitAll(tasks.ToArray());
            }
        }
    }
}
mirror222 commented 3 months ago

Fix #2435

avataron commented 3 months ago

I've installed the 5.0.19 from Nuget and this problem keeps occurring. I had to load all entries to a collection to mitigate this problem, in order to avoid the FindOne() and FindById().

mirror222 commented 3 months ago

I've installed the 5.0.19 from Nuget and this problem keeps occurring. I had to load all entries to a collection to mitigate this problem, in order to avoid the FindOne() and FindById().

see https://github.com/mbdavid/LiteDB/issues/2435

avataron commented 3 months ago

I've installed the 5.0.19 from Nuget and this problem keeps occurring. I had to load all entries to a collection to mitigate this problem, in order to avoid the FindOne() and FindById().

see #2435

Yeah, I read that before. In the end of that, someone says "Note that we rolled this fix into 5.0.19 and found that it resolves (...)" but as I stated, the 5.0.19 still throws bug to me.

GalensGan commented 1 month ago

same issue for me with v5.0.19