Fix media creation being ratelimited for appservices (#19335)

Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
This commit is contained in:
Tulir Asokan 2026-01-06 19:34:38 +02:00 committed by GitHub
parent 1500733f4a
commit ac6463c6da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 9 deletions

1
changelog.d/19335.bugfix Normal file
View file

@ -0,0 +1 @@
Fixed parallel calls to `/_matrix/media/v1/create` being ratelimited for appservices even if `rate_limited: false` was set in the registration. Contributed by @tulir @ Beeper.

View file

@ -60,15 +60,16 @@ class CreateResource(RestServlet):
# If the create media requests for the user are over the limit, drop them.
await self._create_media_rate_limiter.ratelimit(requester)
(
reached_pending_limit,
first_expiration_ts,
) = await self.media_repo.reached_pending_media_limit(requester.user)
if reached_pending_limit:
raise LimitExceededError(
limiter_name="max_pending_media_uploads",
retry_after_ms=first_expiration_ts - self.clock.time_msec(),
)
if not requester.app_service or requester.app_service.is_rate_limited():
(
reached_pending_limit,
first_expiration_ts,
) = await self.media_repo.reached_pending_media_limit(requester.user)
if reached_pending_limit:
raise LimitExceededError(
limiter_name="max_pending_media_uploads",
retry_after_ms=first_expiration_ts - self.clock.time_msec(),
)
content_uri, unused_expires_at = await self.media_repo.create_media_id(
requester.user