Skip to content

Conversation

@erikjohnston
Copy link
Member

@erikjohnston erikjohnston commented Jun 25, 2025

When a request gets ratelimited we (optionally) wait ~500ms before returning to mitigate clients that like to tightloop on request failures. However, this is currently implemented by pausing request processing when we check for ratelimits, which might be deep within request processing, and e.g. while locks are held. Instead, let's hoist the pause to the very top of the HTTP handler.

Hopefully, this mitigates the issue where a user sending lots of events to a single room can see their requests time out due to the combination of the linearizer and the pausing of the request. Instead, they should see the requests 429 after ~500ms.

The first commit is a refactor to pass the Clock to AsyncResource, the second commit is the behavioural change.

@erikjohnston erikjohnston marked this pull request as ready for review June 25, 2025 12:36
@erikjohnston erikjohnston requested a review from a team as a code owner June 25, 2025 12:36
@erikjohnston erikjohnston enabled auto-merge (squash) June 25, 2025 14:03
@erikjohnston erikjohnston merged commit 0779587 into develop Jun 25, 2025
43 checks passed
@erikjohnston erikjohnston deleted the erikj/lift_ratelimit_pause branch June 25, 2025 14:32
Comment on lines +403 to +405
def __init__(
self, clock: Clock, canonical_json: bool = False, extract_context: bool = False
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that we expose DirectServeJsonResource in the module API, and this change is backward-incompatible for modules that expose endpoints.

Unfortunately therefore I think we need to revert it/find a way to achieve a similar result while remaining backwards-compatible.

erikjohnston added a commit that referenced this pull request Jun 26, 2025
As that appears in the module API.

Broke in #18595.
erikjohnston added a commit that referenced this pull request Jun 26, 2025
As that appears in the module API.

Broke in #18595.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants