-
Notifications
You must be signed in to change notification settings - Fork 522
Lift pausing on ratelimited requests to http layer #18595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
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 @@ | ||
| Better handling of ratelimited requests. |
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
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
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 |
|---|---|---|
|
|
@@ -67,14 +67,15 @@ | |
| from synapse.api.errors import ( | ||
| CodeMessageException, | ||
| Codes, | ||
| LimitExceededError, | ||
| RedirectException, | ||
| SynapseError, | ||
| UnrecognizedRequestError, | ||
| ) | ||
| from synapse.config.homeserver import HomeServerConfig | ||
| from synapse.logging.context import defer_to_thread, preserve_fn, run_in_background | ||
| from synapse.logging.opentracing import active_span, start_active_span, trace_servlet | ||
| from synapse.util import json_encoder | ||
| from synapse.util import Clock, json_encoder | ||
| from synapse.util.caches import intern_dict | ||
| from synapse.util.cancellation import is_function_cancellable | ||
| from synapse.util.iterutils import chunk_seq | ||
|
|
@@ -308,9 +309,10 @@ class _AsyncResource(resource.Resource, metaclass=abc.ABCMeta): | |
| context from the request the servlet is handling. | ||
| """ | ||
|
|
||
| def __init__(self, extract_context: bool = False): | ||
| def __init__(self, clock: Clock, extract_context: bool = False): | ||
| super().__init__() | ||
|
|
||
| self._clock = clock | ||
| self._extract_context = extract_context | ||
|
|
||
| def render(self, request: "SynapseRequest") -> int: | ||
|
|
@@ -329,7 +331,12 @@ async def _async_render_wrapper(self, request: "SynapseRequest") -> None: | |
| request.request_metrics.name = self.__class__.__name__ | ||
|
|
||
| with trace_servlet(request, self._extract_context): | ||
| callback_return = await self._async_render(request) | ||
| try: | ||
| callback_return = await self._async_render(request) | ||
| except LimitExceededError as e: | ||
| if e.pause: | ||
| self._clock.sleep(e.pause) | ||
| raise | ||
|
|
||
| if callback_return is not None: | ||
| code, response = callback_return | ||
|
|
@@ -393,8 +400,10 @@ class DirectServeJsonResource(_AsyncResource): | |
| formatting responses and errors as JSON. | ||
| """ | ||
|
|
||
| def __init__(self, canonical_json: bool = False, extract_context: bool = False): | ||
| super().__init__(extract_context) | ||
| def __init__( | ||
| self, clock: Clock, canonical_json: bool = False, extract_context: bool = False | ||
| ): | ||
|
Comment on lines
+403
to
+405
Member
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. It turns out that we expose Unfortunately therefore I think we need to revert it/find a way to achieve a similar result while remaining backwards-compatible. |
||
| super().__init__(clock, extract_context) | ||
| self.canonical_json = canonical_json | ||
|
|
||
| def _send_response( | ||
|
|
@@ -450,8 +459,8 @@ def __init__( | |
| canonical_json: bool = True, | ||
| extract_context: bool = False, | ||
| ): | ||
| super().__init__(canonical_json, extract_context) | ||
| self.clock = hs.get_clock() | ||
| super().__init__(self.clock, canonical_json, extract_context) | ||
| # Map of path regex -> method -> callback. | ||
| self._routes: Dict[Pattern[str], Dict[bytes, _PathEntry]] = {} | ||
| self.hs = hs | ||
|
|
||
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.