summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorSven Mäder <rda0@users.noreply.github.com>2025-01-24 20:58:01 +0100
committerGitHub <noreply@github.com>2025-01-24 19:58:01 +0000
commit9c5d08fff8d66a7cc0e2ecfeeb783f933a778c2f (patch)
tree4ed921cdf835dfdc0002840baa1e796209ef9b00 /synapse/api
parentContrib: Docker: updates PostgreSQL version in `docker-compose.yml` (#18089) (diff)
downloadsynapse-9c5d08fff8d66a7cc0e2ecfeeb783f933a778c2f.tar.xz
Ratelimit presence updates (#18000)
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/ratelimiting.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/synapse/api/ratelimiting.py b/synapse/api/ratelimiting.py

index b80630c5d3..229329a5ae 100644 --- a/synapse/api/ratelimiting.py +++ b/synapse/api/ratelimiting.py
@@ -275,6 +275,7 @@ class Ratelimiter: update: bool = True, n_actions: int = 1, _time_now_s: Optional[float] = None, + pause: Optional[float] = 0.5, ) -> None: """Checks if an action can be performed. If not, raises a LimitExceededError @@ -298,6 +299,8 @@ class Ratelimiter: at all. _time_now_s: The current time. Optional, defaults to the current time according to self.clock. Only used by tests. + pause: Time in seconds to pause when an action is being limited. Defaults to 0.5 + to stop clients from "tight-looping" on retrying their request. Raises: LimitExceededError: If an action could not be performed, along with the time in @@ -316,9 +319,8 @@ class Ratelimiter: ) if not allowed: - # We pause for a bit here to stop clients from "tight-looping" on - # retrying their request. - await self.clock.sleep(0.5) + if pause: + await self.clock.sleep(pause) raise LimitExceededError( limiter_name=self._limiter_name,