You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
where my ex is 1441268386 and Date.now() was 1441268386507 meaning it was -507ms over expiration.
The problem here is that error is in a weird double array so the error check doesn't catch it and my responses to limit.get(function(err, limit) { ... }); always show n remaining so it effectively doesn't rate limit at all.
I assume other people would have run into this. I was using a duration of 1 second and I'm hitting redis pretty hard concurrently.
Is this line stripping off the milliseconds and just making it accurate to the second?
duration: 1000 is the lowest I call it with and it can be up to 60000. I'm testing some changes to keep the milliseconds on a fork that looks to be a little better for how hard I'm hitting it. I'll submit a pull request once I'm sure it's working well and stable if you're interested. Not sure what you want to do about that error message being wrapped in two arrays or the best way to even handle that error.
Sorry I haven't gotten to this yet. I've been swamped lately. I did run those tests and everything looked good so I want to look into this more once I have a chance!
You can see the while loop I added. It basically causes the test to wait until it's going to be on the cusp of a rounding issue. It looks like the rounding is causing redis to cleanup the counts before the millisecond resolution. We're seeing issues with this when running on AWS with Elasticache because we get millisecond response times.
By removing the rounding, it looks to fix that issue...but it breaks a few other tests because now it's giving milliseconds back from the calls and not seconds. Thoughts?
You can see the while loop I added. It basically causes the test to wait
until it's going to be on the cusp of a rounding issue. It looks like the
rounding is causing redis to cleanup the counts before the millisecond
resolution. We're seeing issues with this when running on AWS with
Elasticache because we get millisecond response times.
By removing the rounding, it looks to fix that issue...but it breaks a few
other tests because now it's giving milliseconds back from the calls and
not seconds. Thoughts?
—
Reply to this email directly or view it on GitHub #11 (comment).
Sorry for the delay.
I think I found an easy way to reproduce it, take a look at 499e3fc. please checkout this commit and tell me if it reproduce your bug or something else (last test fails without the while addition).
I will add a constant test with fakeredis right after we'll merge #12.
I'll look into this soon. I don't think just changing redis to fakeredis would make it fail for the same reason unless fakeredis handles expiration differently.
just to make sure I understand - the reset is set to the floor value of the second even though Date.now() is already bigger?
For example for epoch 1441268386507 the reset is 1441268386000 already when setting it?
Just to make sure, is it reproducible with duration 2000? what about 1500?
Activity
noamshemesh commentedon Sep 3, 2015
Thanks @thoop
the last line that you mention strips the millis as you say.
do you call the rate limiter with
duration: 1000or withduration: 1?thoop commentedon Sep 3, 2015
duration: 1000is the lowest I call it with and it can be up to60000. I'm testing some changes to keep the milliseconds on a fork that looks to be a little better for how hard I'm hitting it. I'll submit a pull request once I'm sure it's working well and stable if you're interested. Not sure what you want to do about that error message being wrapped in two arrays or the best way to even handle that error.Thanks for the quick response!
noamshemesh commentedon Sep 3, 2015
I tried to write a test that reproduce this issue, and it passed.
any thoughts?
thoop commentedon Sep 3, 2015
Let me see if I can reproduce it. Are you actually using redis in your test or do you have it mocked out?
noamshemesh commentedon Sep 3, 2015
actual redis. the tests are in test directory, you can run them by executing
mocha test/thoop commentedon Sep 8, 2015
Sorry I haven't gotten to this yet. I've been swamped lately. I did run those tests and everything looked good so I want to look into this more once I have a chance!
thoop commentedon Sep 16, 2015
I modified the test and got it to fail reliably around the edge case of the seconds/milliseconds.
In the last test of
test/index.js, change it to be this:You can see the while loop I added. It basically causes the test to wait until it's going to be on the cusp of a rounding issue. It looks like the rounding is causing redis to cleanup the counts before the millisecond resolution. We're seeing issues with this when running on AWS with Elasticache because we get millisecond response times.
By removing the rounding, it looks to fix that issue...but it breaks a few other tests because now it's giving milliseconds back from the calls and not seconds. Thoughts?
noamshemesh commentedon Sep 16, 2015
Hi thoop,
I won't be near a computer until next month. I will take a look then.
Thanks though!
On Wed, Sep 16, 2015, 10:06 Todd Hooper notifications@github.com wrote:
noamshemesh commentedon Oct 12, 2015
Sorry for the delay.
I think I found an easy way to reproduce it, take a look at 499e3fc. please checkout this commit and tell me if it reproduce your bug or something else (last test fails without the while addition).
I will add a constant test with fakeredis right after we'll merge #12.
thoop commentedon Oct 12, 2015
I'll look into this soon. I don't think just changing redis to fakeredis would make it fail for the same reason unless fakeredis handles expiration differently.
noamshemesh commentedon Oct 21, 2015
Can you check please if #13 solves your issue?
thoop commentedon Oct 21, 2015
Sure, thanks! I'll report back.
noamshemesh commentedon Dec 21, 2015
closing due to inactivity
brandonros commentedon Sep 20, 2019
I am able to recreate this with the latest version from npm (3.3.1).
{ max: 4, duration: 1000 }noamshemesh commentedon Sep 20, 2019
just to make sure I understand - the
resetis set to the floor value of the second even thoughDate.now()is already bigger?For example for epoch
1441268386507the reset is1441268386000already when setting it?Just to make sure, is it reproducible with duration 2000? what about 1500?
brandonros commentedon Sep 20, 2019
does that help you, or do you need me to log
Date.now()too? I changed the bucket definition to{ max: 20, duration: 5000 }and it still happens.noamshemesh commentedon Sep 21, 2019
can you use the resetMs instead?
brandonros commentedon Sep 21, 2019
https://github.com/tj/node-ratelimiter#example
That code is from your example.
I switched to a different package, thanks!