Closed
Description
Description
Hey, I've noticed that the hit count isn't reset although the TTL is reached.
- express-rate-limit@7.4.1
- rate-limit-redis@4.2.0
- ioredis@5.4.1
logs:
2025-05-29 09:10:05.828 | GET / 200 0.677 ms - 15
2025-05-29 09:10:05.828 | x-ratelimit-remaining: 99604 x-ratelimit-reset: 1748506206
2025-05-29 09:10:05.840 | GET / 200 0.901 ms - 15
2025-05-29 09:10:05.840 | x-ratelimit-remaining: 99603 x-ratelimit-reset: 1748506211
So the rate limit window has changed but the remaining limit wasn't reset
I believe it has to do with this line
rate-limit-redis/source/scripts.ts
Line 12 in a2ece35
If there's a race condition between incrementing the hit counter and the TTL, the hit counter will be incremented and the rate limit window will be reset, but the behaviour should be to also reset the hit counter since the TTL was reached
Library version
4.2.0
Node version
v18.20.6
Typescript version (if you are using it)
No response
Module system
ESM