Skip to content

Hit count not reset when TTL is reached #216

Closed
@danielpires

Description

@danielpires

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

Implementation:
Image

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

if timeToExpire <= 0 or ARGV[1] == "1"

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions