fix(auth): make Redis rate-limit counters atomic#9
Merged
Chat2DB-Pro merged 1 commit intoJun 18, 2026
Merged
Conversation
Run INCR and first-hit PEXPIRE in one Lua script for auth rate limits and failed-login counters, matching EdgeFunctionRateLimiter and preventing TTL-less keys that never reset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RateLimiterService的 Redis 路径改为 Lua 脚本原子执行INCR+ 首次PEXPIREcheckRate(OTP/敏感操作限流)与recordFailure(登录失败计数)两条路径increment+expire调用问题(为何必须修)
原先分两步:
若在
EXPIRE前进程崩溃,Redis 会留下无 TTL 的计数 key,窗口永不重置 → 用户永久 429;失败计数同理。同仓库EdgeFunctionRateLimiter已用相同 Lua 模式修复并附有注释说明。Test plan
mvn test -Dtest=RateLimiterServiceTest(6 tests passed)execute(script)被调用且opsForValue().increment不再用于限流计数