-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛 [Bug]: memory: protect field access with lock to avoid possible data race #2360
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
@UtopiaGitHub can you help us with a pull request and also do the fix in the storage repository |
Yes. I commit the pull request to fix the bug. Thanks for your condition. |
@ReneWerner87 @UtopiaGitHub I made the comment in the PR too. But I think Conn() is suppose to return a pointer to the memory field. The other storage providers return a pointer. |
Bug Description
Fixed inconsistency and also potential data race in memory/memory.go:
s.db is read/written 8 times in memory/memory.go; 7 out of 8 times it is protected by s.mux.RLock()/Lock(); 1 out of 8 times it is read without a Lock, which is in func Conn() on L142.
A data race may happen when Conn() and other func like Set() are called in parallel.
The fix is to protect the access to s.db and save the result to a local variable.
How to Reproduce
Steps to reproduce the behavior:
Nil
Expected Behavior
Data Race
Fiber Version
v2.42.0
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: