question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:11

github_iconTop GitHub Comments

1reaction
huyhucommented, Apr 18, 2020

@huyhu You should create a fork of LiteDB, make your changes there and then submit a pull request.

@lbnascimento Could you please review the pull request?

0reactions
Pete-PlaytimeSolutionscommented, Jan 13, 2023

Just an update, The suggested fix by @huyhu solved my issues, but have had to fork the code base, hopefully temporarily 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write lock being released without being held
I have a situation whereby ReadWriterLockSlim is throwing the exception "System.Threading.SynchronizationLockException - The write lock is being ...
Read more >
ReaderWriterLockSlim Class (System.Threading)
Represents a lock that is used to manage access to a resource, allowing multiple threads for reading or exclusive access for writing.
Read more >
C# – Write lock being released without being held
I have a situation whereby ReadWriterLockSlim is throwing the exception "System.Threading.SynchronizationLockException – The write lock is being released ...
Read more >
Best Practices When Using the Lock Statement
When synchronizing access to data in multithreaded C# applications, it is common to use the lock statement—in part due to its simple syntax....
Read more >
Synchronization primitives + async/await = trouble
System.Threading.SynchronizationLockException: 'The read lock is being released without being held.' The code looked fairly straightforward and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found