Skip to content

Commit

Permalink
Update LockService.cs
Browse files Browse the repository at this point in the history
resolving issue of 
"ClassName": "System.Threading.SynchronizationLockException",
"Message": "The read lock is being released without being held.",
  • Loading branch information
mathis1337 authored Jan 25, 2023
1 parent cd1ae01 commit 15b3f6b
Showing 1 changed file with 11 additions and 3 deletions.
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()
}
}
}
}
}

0 comments on commit 15b3f6b

Please # to comment.