FIX: sliding window end time in rate limiter (PR #11691)

If the sliding window size is N seconds, then a moment at the Nth second should be considered as the moment outside of the sliding window.

Otherwise, if the sliding window is already full, at the Nth second, a new call wouldn’t be allowed, but a time to wait before the next call would be equal to zero, which is confusing.

In other words, the end of the time range shouldn’t be included in the sliding window. Let’s say we start at the second 0, and the sliding window size is 10 seconds. In the current version of Rate Limiter, this sliding window will be considered as a time range [0, 10] (including the end of the range), which actually is 11 seconds in length.

After this fix, the time range will be considered as [0, 10) (excluding the end of the range), which is exactly 10 seconds in length.

GitHub

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

Thanks, this is very clear and a good fix.