Fix rate limiter blocking the first requests

If the server just started, expireTime can become negative. Therefore, the first uninitialized values will not be made available.
This commit is contained in:
games647
2022-01-14 13:20:44 +01:00
parent 17234a791b
commit e0f823cbe4

View File

@ -25,6 +25,8 @@
*/
package com.github.games647.fastlogin.core;
import java.util.Arrays;
/**
* Limit the number of requests with a maximum size. Each requests expire after the specified time making it available
* for another request.
@ -38,6 +40,9 @@ public class RateLimiter {
public RateLimiter(int maxLimit, long expireTime) {
this.requests = new long[maxLimit];
this.expireTime = expireTime;
// fill the array with the lowest values, so that the first uninitialized values will always expire
Arrays.fill(requests, Long.MIN_VALUE);
}
/**