Fix a long-standing bug which meant that rate limiting was not restrictive enough in some cases. (#13018)

This commit is contained in:
reivilibre 2022-06-15 15:11:55 +01:00 committed by GitHub
parent 417f4cf40b
commit 0dbdc39940
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 12 deletions

View file

@ -128,6 +128,9 @@ class Ratelimiter:
performed_count = action_count - time_delta * rate_hz
if performed_count < 0:
performed_count = 0
# Reset the start time and forgive all actions
action_count = 0
time_start = time_now_s
# This check would be easier read as performed_count + n_actions > burst_count,
@ -140,7 +143,7 @@ class Ratelimiter:
else:
# We haven't reached our limit yet
allowed = True
action_count = performed_count + n_actions
action_count = action_count + n_actions
if update:
self.actions[key] = (action_count, time_start, rate_hz)