-
Notifications
You must be signed in to change notification settings - Fork 28
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
RateLimit is not working as expected #20
Comments
A blocked user will eventually become unblocked if they do nothing. Is the session expiring? I'll assume you're aware you need to exit() or similar after the http 429 header to stop any other code from executing in the script. |
Hi @DavidGoodwin , Yes, i am doing exit() after The session is not expiring (i am echoing A blocked user will eventually become unblocked if they do nothing.
Like suddenly i get 429 error (intended behavior) and when i refresh the page within few seconds it gets unblocked and again after 2 or 3 refreshes, it gets blocked again. Should I post a screen recorded video? So, that you can reproduce it properly. |
That sounds like expected behaviour to me, if my memory serves me correctly .... If your rate limiter is setup to allow e.g. 4 requests in a 60 second window, if you refresh / retry e.g. every 15 seconds, I'd expect one request to get through. https://github.com/touhonoob/RateLimit/blob/master/src/RateLimit.php#L57 |
@DavidGoodwin @touhonoob Can you please take a look on this issue? |
Test code - <?php
require_once('vendor/autoload.php');
$server = [
'host' => '192.168.0.1',
'port' => 6379,
'database' => 15,
];
$adapter = new \PalePurple\RateLimit\Adapter\Predis(new \Predis\Client($server));
$rateLimiter = new \PalePurple\RateLimit\RateLimit('login', 5, 60, $adapter);
$count = $rateLimiter->getAllowance('test');
if ($rateLimiter->check('test')) {
http_response_code(200);
echo date('c') . " - OK - {$count} for 5/60\n";
} else {
http_response_code(429);
echo date('c') . " - Blocked; {$count} for 5/60.\n";
exit(0);
} Running this in a while true
do
php test.php
sleep 1
done Output is a bit like :
Which looks correct to me from my hazy memory of how it works.... Namely the bucket fills up, and we then get a 'go' every 5/60 (12 seconds). |
This issue not resolved for me + i also faced this same issue #17 for Race Conditions |
Moved my integration from this project to https://github.com/nikolaposa/rate-limit . I also implemented exponential backoff. Thanks for your awesome open-source contribution! |
Hi @touhonoob ,
Great work! I am just having a problem while setting this up. I am using this configuration and soemtime it's working and sometimes it not.
When a user is blocked and he keeps reloading that tab. Then sometimes user gets passed and sometimes not passed even if the user is blocked. I don't know why this is happening can you please help me with that?
Thanks,
Rohit Kumar
The text was updated successfully, but these errors were encountered: