-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[11.x] Allow list of rate limiters without requiring unique keys #53177
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
4958a8d
to
7dcd17c
Compare
40c0f6f
to
4407e4c
Compare
@gcg wasn't this PR all about that you no longer need to give unique names? |
Still did not test ALL possible combinations but I was using the exact same example w/out giving unique names and after this PR, those 2 limiters that returns multiple limits in an array w/out unique names started failing all requests. I will share more information but giving unique key names manually seems to be working and it's clearly documented so I am in the blame here :) I am reporting live here just in case it happens to someone else. |
Thanks for letting us know, @gcg. Please let us know what you find out. My gut feeling is that your previous set up, sharing the same keys, was likely not working as expected even if it seemed to be working. Keep me posted. |
And sorry for the troubles! |
yeah, you are probably right. I had 2 limiters that returns list limits, one of them is so rarely used and the other route has it's own custom rate limits built in predating laravel mw, even if the ratelimiter didn't work before for that case, I probably didn't notice and only noticed once we started failing requests.
I redeployed rate limiters after uniquely naming everything and now it's back to normal.
It's not your fault that I missed the warning in the documentation, as u stated, it wasn't probably working as it should from the beginning. |
This PR ensures that rate limiters specifying multiple limits will always have unique keys.
The issue.
This rate limiter will always fail. No request would ever get through. Zero. Nada.
This is because both limits share the same key. The docs specify that If you're assigning multiple rate limits segmented by identical by values, you should ensure that each by value is unique
This is fine, but also can be something easily forgotten; bit of a footgun.
The improvement
This PR attempts to improve the situation by ensuring that when a list of limits has duplicate keys they are modified to be unique.
In this above example, the first and the last limits would have their key modified to be unique.
Although this is a breaking change, it only breaks in already broken situations, so I see this as an overall improvement.
I don't feel like we need to update the docs. This is just a fallback fix for those rare times it is held wrong.
fixes #53157