Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update LockService.cs to fix "The read lock is being released without being held" error. Fix for #641, 1637, 1993, 2017 #2280

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions LiteDB/Engine/Services/LockService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ public void ExitTransaction()
{
// if current thread are in reserved mode, do not exit transaction (will be exit from ExitExclusive)
if (_transaction.IsWriteLockHeld) return;

_transaction.ExitReadLock();

//This can be called when a lock has either been released by the slim or somewhere else therefore there is no lock to release from ExitReadLock()
if (_transaction.IsReadLockHeld)
{
try
{
_transaction.ExitReadLock();
}
catch { }
}
}

/// <summary>
Expand Down Expand Up @@ -148,4 +156,4 @@ public void Dispose()
}
}
}
}
}