diff --git a/synapse/util/ratelimitutils.py b/synapse/util/ratelimitutils.py index 85e86b1b06a5..1166ffd021e8 100644 --- a/synapse/util/ratelimitutils.py +++ b/synapse/util/ratelimitutils.py @@ -140,8 +140,11 @@ def ratelimit(self, host: str) -> "Iterator[defer.Deferred[None]]": self._on_exit(request_id) async def _on_enter_with_tracing(self, request_id: object) -> None: + # We may raise a `LimitExceededError`, in which case we avoid tracing. + d = self._on_enter(request_id) + with start_active_span("ratelimit wait"), queue_wait_timer.time(): - await self._on_enter(request_id) + await d def _on_enter(self, request_id: object) -> "defer.Deferred[None]": time_now = self.clock.time_msec()