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

Race condition in pesimistic concurrency management #36

Closed
Narvalex opened this issue Jul 14, 2017 · 5 comments
Closed

Race condition in pesimistic concurrency management #36

Narvalex opened this issue Jul 14, 2017 · 5 comments

Comments

@Narvalex
Copy link

I will always grow with new Guids, without any cleaning being performed in the concurrent dictionary of semaphores by Guid

@gautema
Copy link
Owner

gautema commented Jul 14, 2017

Do you actually get an exception? They should be removed from the dictionary when the are removed from the MemoryCache. Line 27 in CacheRepository is where the callback is registered.

https://github.com/gautema/CQRSlite/blob/master/Framework/CQRSlite/Cache/CacheRepository.cs#L27

@Narvalex
Copy link
Author

You are right. Thanks

@Narvalex
Copy link
Author

I think there is still a chance of a race condition. If the lock is removed just after a thread grabs it, a second thread will create a new entry in the dictionary and there will be two concurrent threads racing for the same stream. Makes any sense?

@Narvalex Narvalex reopened this Jul 20, 2017
@Narvalex Narvalex changed the title The cache repository would run into an OutOfMemoryException Race condition in pesimistic concurrency management Jul 20, 2017
@gautema
Copy link
Owner

gautema commented Jul 20, 2017

While this is so unlikely it will probably never happen, it will just behave like a when the regular repository gets two commands on the same time. If an exception is thrown, it will be removed from the cache again

@Narvalex
Copy link
Author

Ok, I am agree that there is mechanism to recover from it, but the pesimistic lock is a bit optimistic, just a bit indeed. Maybe we should point out that, since Im sure there are guys that might use this approach for high contention scenarios where there is not a mechanism to recover from a failure.

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

No branches or pull requests

2 participants