mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
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:
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user