fix(rate-limit): IP 限流补充 Redis 异常 Fail-Open 放行
This commit is contained in:
@@ -70,8 +70,14 @@ public class IpRateLimitFilter extends OncePerRequestFilter {
|
|||||||
String key = StrUtil.format(RedisConstants.RateLimit.IP, ip);
|
String key = StrUtil.format(RedisConstants.RateLimit.IP, ip);
|
||||||
long windowMs = ipConfig.getWindow().toMillis();
|
long windowMs = ipConfig.getWindow().toMillis();
|
||||||
|
|
||||||
// 执行滑动窗口计数(Lua 原子操作)
|
// 执行滑动窗口计数(Lua 原子操作);Redis 异常时 Fail-Open 放行
|
||||||
Long count = SlidingWindowScript.execute(redisTemplate, key, windowMs);
|
Long count;
|
||||||
|
try {
|
||||||
|
count = SlidingWindowScript.execute(redisTemplate, key, windowMs);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("IP 限流 Redis 异常,Fail-Open 放行 ip={}", ip, e);
|
||||||
|
count = null;
|
||||||
|
}
|
||||||
|
|
||||||
int limit = ipConfig.getLimit();
|
int limit = ipConfig.getLimit();
|
||||||
int current = count != null ? count.intValue() : 0;
|
int current = count != null ? count.intValue() : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user