From 15b3f6b2a71ee9bcb8ed26da28cc896d4c175594 Mon Sep 17 00:00:00 2001 From: Mathis <20599614+mathis1337@users.noreply.github.com> Date: Wed, 25 Jan 2023 09:43:25 -0600 Subject: [PATCH] Update LockService.cs resolving issue of "ClassName": "System.Threading.SynchronizationLockException", "Message": "The read lock is being released without being held.", --- LiteDB/Engine/Services/LockService.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/LiteDB/Engine/Services/LockService.cs b/LiteDB/Engine/Services/LockService.cs index cf4bbad97..1165d8d0b 100644 --- a/LiteDB/Engine/Services/LockService.cs +++ b/LiteDB/Engine/Services/LockService.cs @@ -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 { } + } } /// @@ -148,4 +156,4 @@ public void Dispose() } } } -} \ No newline at end of file +}