summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorreivilibre <oliverw@matrix.org>2022-06-15 15:11:55 +0100
committerGitHub <noreply@github.com>2022-06-15 14:11:55 +0000
commit0dbdc3994063245900501a95b348f50d943fd72b (patch)
tree0d31f32f97f8b4ca20cb386be912cb844625966f /synapse/api
parentDon't use keyword arguments when initialising modules (#13060) (diff)
downloadsynapse-0dbdc3994063245900501a95b348f50d943fd72b.tar.xz
Fix a long-standing bug which meant that rate limiting was not restrictive enough in some cases. (#13018)
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/ratelimiting.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/synapse/api/ratelimiting.py b/synapse/api/ratelimiting.py
index 849c18ceda..54d13026c9 100644
--- a/synapse/api/ratelimiting.py
+++ b/synapse/api/ratelimiting.py
@@ -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)