Skip to content

[BUG] FindById throws SynchronizationLockException: The read lock is being released without being held. #1637

@huyhu

Description

@huyhu

Version
5.0.5

Describe the bug
FindById sporadically throws System.Threading.SynchronizationLockException: "The read lock is being released without being held."

Code to Reproduce
Here how I use FindById -it is hard to reproduce the issue though

public T FindById<T>(int id)
{
    var data = database.GetCollection<T>(typeof(T).Name).FindById(new BsonValue(id));

    if (Equals(data, default(T)))
    {
        throw new InvalidOperationException($"Cannot find {typeof(T).Name} with id {id}");
    }
    return data;
}

Expected behavior
No exceptions.

Screenshots/Stacktrace
"ClassName": "System.Threading.SynchronizationLockException",
"Message": "The read lock is being released without being held.",
"Data": null,
"InnerException": null,
"HelpURL": null,
"StackTraceString": " at System.Threading.ReaderWriterLockSlim.ExitReadLock()\r\n at LiteDB.Engine.TransactionMonitor.ReleaseTransaction(TransactionService transaction)\r\n at LiteDB.Engine.QueryExecutor.ExecuteQuery(Boolean executionPlan)\r\n at LiteDB.Engine.LiteEngine.Query(String collection, Query query)\r\n at LiteDB.LiteQueryable1.<ToDocuments>d__26.MoveNext()\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()\r\n at

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions