Closed alno closed 13 years ago
Good catch. I'm trying to think of a reason we can't just set bucket_expiry to the same value as bucket_span by default and raise an exception if the user tries to set it to larger than bucket_span. Thoughts?
https://github.com/ejfinneran/ratelimit/commit/b5b81dcc488f231b6a7abbdeb87c7ddf247b4029
Hmm.. Yes, i think it solves problem. It was my error in previous post - no need to substract maximum interval because of buckets in it are counted back, not forward.
Consider following test:
It fails.
After 600 seconds of inactivity bucket wasn't expired yet, but it's index is the same again, so it return wrong result in count. Although it's rare case, it's possible to produce wrong results. Also, probability of error increases when increasing interval in count.
One of possible solutions may be restricting bucket_expire to be no more than bucket_span minus maximum interval which may be requested in count.