This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Do not apply ratelimiting on joins to appservices #8139
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
df78b3c
add can_requester_do_action
Half-Shot 1876057
use can_requester_do_action
Half-Shot a588d2d
Add tests for appservice
Half-Shot 1360623
changelog
Half-Shot 9ceae6a
fix types
Half-Shot a7b6072
changelog
Half-Shot ef95f67
reformatted
Half-Shot 99e9c9a
Update changelog.d/8139.bugfix
Half-Shot 9660ae5
Update changelog.d/8139.bugfix
Half-Shot e46fe08
Add docstring
Half-Shot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixes a bug where appservices with ratelimiting disabled would still be ratelimited when joining rooms. This bug was introduced in v1.19.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from typing import Any, Optional, Tuple | ||
|
||
from synapse.api.errors import LimitExceededError | ||
from synapse.types import Requester | ||
from synapse.util import Clock | ||
|
||
|
||
|
@@ -43,6 +44,42 @@ def __init__(self, clock: Clock, rate_hz: float, burst_count: int): | |
# * The rate_hz of this particular entry. This can vary per request | ||
self.actions = OrderedDict() # type: OrderedDict[Any, Tuple[float, int, float]] | ||
|
||
def can_requester_do_action( | ||
self, | ||
requester: Requester, | ||
rate_hz: Optional[float] = None, | ||
burst_count: Optional[int] = None, | ||
update: bool = True, | ||
_time_now_s: Optional[int] = None, | ||
) -> Tuple[bool, float]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, can you also add a docstring here, which mostly just refers to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"""Can the requester perform the action? | ||
|
||
Args: | ||
requester: The requester to key off when rate limiting. The user property | ||
will be used. | ||
rate_hz: The long term number of actions that can be performed in a second. | ||
Overrides the value set during instantiation if set. | ||
burst_count: How many actions that can be performed before being limited. | ||
Overrides the value set during instantiation if set. | ||
update: Whether to count this check as performing the action | ||
_time_now_s: The current time. Optional, defaults to the current time according | ||
to self.clock. Only used by tests. | ||
|
||
Returns: | ||
A tuple containing: | ||
* A bool indicating if they can perform the action now | ||
* The reactor timestamp for when the action can be performed next. | ||
-1 if rate_hz is less than or equal to zero | ||
""" | ||
# Disable rate limiting of users belonging to any AS that is configured | ||
# not to be rate limited in its registration file (rate_limited: true|false). | ||
if requester.app_service and not requester.app_service.is_rate_limited(): | ||
return True, -1.0 | ||
|
||
return self.can_do_action( | ||
requester.user.to_string(), rate_hz, burst_count, update, _time_now_s | ||
) | ||
|
||
def can_do_action( | ||
self, | ||
key: Any, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.