-
Notifications
You must be signed in to change notification settings - Fork 261
Concurrency Issues in StateRepositories #21
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
Comments
Hey jadlr, thanks a lot for bringing up this issue. Yes, you are completely right. The state repositories should be thread safe. That's a bug that should be fixed. Would you be interested in helping to fix this? This would be great. Especially as you have already looked into the problem. I've just released Togglz 2.0.0.Alpha1 which includes some major refactorings. But I think it would make sense to release 1.1.1 based on 1.1.0 to also fix this. Especially because it will take some time to finish Togglz 2.0.0. |
I just created a maintenance branch for 1.1.x here: |
i'll get to it once I have a few hours at hand which might take a bit. |
Sure, I'll also try to find some time to fix this issue. |
Hey jadlr, I reproduce the concurrency issue with What do you think? Will this fix the concurrency issue you ran into? Christian |
wouldn't syncronizing getFeatureState() hurt performance? |
I think as a quick fix it would suffice to synchronize |
Thanks for you comments on this. I also synchronized the And I synchronized
If two threads execute these three steps concurrently, this could happen: If thread A performs step 2 and a thread B enters steps 1 concurrently and later writes the data after A has written it's date, the update of A gets lost. I think it would be better to fix concurrency issue with simple |
You're right, this way it should be safe. |
Thanks you very much for reporting this issue. I'll do some more reviews and then release 1.1.1.Final soon. |
Hi,
I noticed a concurrency bug in the FileBasedStateRepository (writes are not synced) and while implementing a fix for it I noticed that none of the StateRepositories (besides the JDBC Repo) are thread safe, so I thought I'd ask if this is by design? Since you provide a servlet that lets you change the state of StateRepos that are at the same time used by code that leverages togglz I think it would be best to make the StateRepositories thread safe.
In the case of the FileBasedStateRepository this is especially dangerous because the file could be written outside of the JVM while it is written/read by your code. A solution that would depend on the architecture the JVM runs on would be to acquire a FileLock before writing to/reading from it.
Let me know what you think,
jadlr
The text was updated successfully, but these errors were encountered: