Closed skalpel closed 9 months ago
Thank you! It took me a moment, but I believe you are absolutely right and this bug exists in all the storages (async & sync). I'll put up a PR and hope you can help review to make sure we get this right, this time.
Thinking about it again: reset_time
is technically better tied to the newest entry expiring as that is when the full limit will be available again. Deriving retry_after
from reset_time
isn't completely accurate since there will be some capacity before that time.
EDIT: scratch the above thought - I haven't fully thought that through.
Thanks a lot! Please let me know if you need any help including review, testing etc.
Resolved in #202
For the following code:
retry_after
is 50, whereas in this case it should probably be 40, because the event from hit 1 will be removed after 40 seconds, opening the window for the next event (and indeed, when 40 seconds have passed,limiter.hit
will returnTrue
).Current Behaviour
For
MemoryStorage.get_moving_window
events are being iterated from the newest to the oldest one, so the newest one is used as the beginning of the window, while probably the oldest one should be used.Your Environment