-
-
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]: Cache mutex will blocks other requests if any of the cached API is slow. #2057
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 |
can you provide a pull request with some tests that will solve the problem |
@ReneWerner87 @harsh-98 this been manually tested, after #1764 MR the problematic lock has been fixed, please see below:
Also did an automated test with this:
Good point about redundant use of mutex here, that's true, when actual manager does it on it's own, but there's no mentioned bug here (ie slow routes when cached, do not affect other routes). That was the point of #1764 I'll do some tests later to remove redundant mutex. Thanks |
Bug Description
https://github.com/gofiber/fiber/blob/master/middleware/cache/cache.go#L57 The refactored mutex logic in the cache still blocks other requests. The same mutex is used for retrieving cached values and saving the response of cached API. So, if a slow API is cached, it will block the retrieval of cached values for other APIs.
I don't think the mutex is required here. The memory manager itself has rwMutex lock to prevent race conditions. The only behavioral change without mutex is that for the same key, if multiple requests are made simultaneously the response of the last request will override the first request. But since cache implementation only allows saving GET method responses. I don't think saving first response is of importance.
Expected Behavior
Don't block other requests if cached API is slow.
Fiber Version
v2.36.0
Checklist:
The text was updated successfully, but these errors were encountered: