Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Possible occurrence of write lock leakage during high concurrency. #3

Open
ghostclearsky opened this issue Jun 1, 2023 · 0 comments · May be fixed by #4
Open

Possible occurrence of write lock leakage during high concurrency. #3

ghostclearsky opened this issue Jun 1, 2023 · 0 comments · May be fixed by #4

Comments

@ghostclearsky
Copy link

ghostclearsky commented Jun 1, 2023

There is a defect in Wintellect.Threading.ResourceLocks.ResourceLock.Leave where write lock leakage can easily occur in high concurrency scenarios.

The Enter method first acquires the lock and then increments the counter, while the Leave method first releases the lock and then decrements the counter.

This introduces a possibility where, assuming thousands of threads are executing read locks simultaneously and releasing them, and at that moment, one thread acquires a write lock and immediately releases it. In this scenario, it is possible that the counter for the read locks has not yet completed the subtraction operation. When the Leave method is called on this write lock, it mistakenly treats it as a read lock and releases it accordingly. This triggers an exception stating "Read lock was not held when attempting to release," resulting in write lock leakage.

To address this issue, the Leave method should be modified to place the lock release operation (OnLeave(exclusive)) at the bottom. This ensures the atomicity of the lock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant