-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
response-ratelimiting plugin still forwards request after limit is exceeded - Kong 0.7.0 #1096
Comments
@codewaffle I cannot replicate your bug, and once Kong starts answering with Could you please give me the curl commands that you used for adding the API and the plugin? |
I'm doing some more comprehensive testing now to see if I can narrow it down. |
@thefosk I've put together a Vagrantfile + script + supporting demo API that showcases this issue, visible in this gist: https://gist.github.com/codewaffle/b646acbd94cef0b84377 The Vagrantfile will execute the test during the provisioning step. |
@codewaffle thanks for the replication instructions. The first thing I noticed is that I ran my test with the Rate-Limiting plugin and not the Response Rate-Limiting plugin, so that's why I couldn't replicate it. The Response Rate-Limiting plugin is a very particular plugin, that although it supports custom limits, it also introduces some limitations (as discussed in #733 (comment)), especially this part:
I can go ahead and implement the following fix when there is only one quota:
But I am open to hear any feedback. |
From the user's perspective, the request was blocked, no matter if they tripped a single rate limit out of one, or a single rate limit out of fifty.. the user CAN NOT get results out of any request if they have exceeded any individual limit applied to an API, so it is extremely unnatural that these requests could actually have state-changing effects internally. This could be made workable if Kong presented headers that the backend API when limits have been tripped, and then my API could be modified to account for that... but then we're moving a big chunk of the rate limiting problem to the external backend API - which is exactly the problem I'm trying to avoid with Kong. |
@codewaffle how many custom limits did you setup in the plugin? |
I'm only using two at the moment - but definitely more than one, so your proposed workaround would not help directly. After reading through #733 again I'm starting to understand the reasoning behind how it currently works - a client wants to READ something and is only allowed to read it x times per period. The extraneous requests to the server can be ignored, because the backend call itself has no side effects. In my use case, a client wants to trigger a heavy background process, and I'm gating it with two limits: a 'call' limit and a 'fail' limit - if the client triggers failure results too quickly, I don't want them to be able to make normal calls either - so blocking off the entire API if ANY limit is tripped is exactly what I desire, and how I originally interpreted the documentation. So, it looks like I just misunderstood how the plugin was supposed to work.. if a boolean flag could be added to cause requests to be pre-emptively discarded if any rate limits are currently met, this would still fit my use case perfectly - otherwise it looks like moving rate limiting directly into my API is the way to go. |
This is a good idea. So there is a combination of solutions that we can take:
To avoid having this exception, either
I am more tempted to merge the two so that |
The bulk problem can also affect non-bulk requests: if the user makes many requests at once, Kong won't know when to start limiting until those requests start returning responses. As such, adding more distinctions between bulk and non-bulk is just going to muddy things further, in my opinion - Currently, the only way I can think of to reject the request without causing the backend to fully process it, is to pass rate limiting info to the backend (ala x-consumer-id) and inspect it on a per-endpoint basis, allowing the backend to reject early - the endpoint already knows it wants to consume a DEMO credit (it must, to construct the X-Kong-Limit header), so reading the incoming request headers to see if Kong thinks they have any credits left doesn't seem out of the question, and means Kong doesn't need to know any specifics about the endpoint. |
I'm running 0.7.0 using Docker and the official image, linked to a vanilla Cassandra container.
My custom response headers are triggering the plugin properly - x-ratelimit-remaining-test-hour decrements to 0 and Kong starts kicking back 429 responses for every request from that IP - perfect, except those requests are still being forwarded to the backend without any indicator that they should be rate limited (and I suspect they shouldn't be reaching the backend at all).
The text was updated successfully, but these errors were encountered: