From e0f823cbe4b4f3095c5c0723ab3095e9060d2dd8 Mon Sep 17 00:00:00 2001 From: games647 Date: Fri, 14 Jan 2022 13:20:44 +0100 Subject: [PATCH] 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. --- .../java/com/github/games647/fastlogin/core/RateLimiter.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java b/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java index b61ec601..cb228892 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/RateLimiter.java @@ -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); } /**