Update LockService.cs to fix "The read lock is being released without being held" error. Fix for #641, 1637, 1993, 2017 #2280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix for:
#641, #1637, #1993, #2017
resolving issue of
"ClassName": "System.Threading.SynchronizationLockException",
"Message": "The read lock is being released without being held.",
Issue is that the ReaderWriterLockSlim can be released or not set if not needed and so the code as it stands will attempt to call ExitReadLock() and this will throw an unhandled exception error.
I've added and If statement check to ensure there is exactly a ReadLock and also put it in a try catch in the event the Read is released within the small fraction of time the exit is called, so the remaining execution of code can run as needed.
I suspect that this ReleaseTransaction method that is referenced is multiple places is being called, or its just the lock is released too soon, but this fixes that until a better solution can be implemented.
I Know other have had this issue, so it would be good to get the PR in or if there is a better place to resolve this let me know and I'll investigate.