Skip to content

Misleading reset value #43

@xdmnl

Description

@xdmnl

Since a new member is added to the sorted set every time the rate limiter is accessed, the sorted set will keep growing even if the limit is reached.
It leads to situation where, clients that are waiting for the limit to be reached before retrying when specified can end up in a loop of requests that will be limited.

Simplified example:

limit = 2
duration = 3
time sorted set result
t0.0 [0.0] {remaining: 2, reset: 3.0}
t0.1 [0.0, 0.1] {remaining: 1, reset: 3.0}
t0.2 [0.0, 0.1, 0.2] {remaining: 0, reset: 3.0}
t3.0 [0.1, 0.2, 3.0] {remaining: 0, reset: 3.1}
t3.1 [0.2, 3.0, 3.1] {remaining: 0, reset: 3.2}

Shouldn't the rate limiter remove the newly added member if remaining is <= 0?
With my simplified example we would have something like:

time sorted set result
t0.0 [0.0] {remaining: 2, reset: 3.0}
t0.1 [0.0, 0.1] {remaining: 1, reset: 3.0}
t0.2 [0.0, 0.1] {remaining: 0, reset: 3.0}
t3.0 [0.1, 3.0] {remaining: 1, reset: 3.1}
t3.1 [3.0, 3.1] {remaining: 0, reset: 6.0}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions