Skip to content

Commit e0f823c

Browse files
author
games647
committed
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.
1 parent 17234a7 commit e0f823c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
package com.github.games647.fastlogin.core;
2727

28+
import java.util.Arrays;
29+
2830
/**
2931
* Limit the number of requests with a maximum size. Each requests expire after the specified time making it available
3032
* for another request.
@@ -38,6 +40,9 @@ public class RateLimiter {
3840
public RateLimiter(int maxLimit, long expireTime) {
3941
this.requests = new long[maxLimit];
4042
this.expireTime = expireTime;
43+
44+
// fill the array with the lowest values, so that the first uninitialized values will always expire
45+
Arrays.fill(requests, Long.MIN_VALUE);
4146
}
4247

4348
/**

0 commit comments

Comments
 (0)