diff --git a/changelog.d/18699.misc b/changelog.d/18699.misc new file mode 100644 index 000000000..52498192c --- /dev/null +++ b/changelog.d/18699.misc @@ -0,0 +1 @@ +Reduce log spam when client stops downloading media while it is being streamed to them. diff --git a/synapse/media/_base.py b/synapse/media/_base.py index 2e48d2fdc..29911dab7 100644 --- a/synapse/media/_base.py +++ b/synapse/media/_base.py @@ -380,12 +380,13 @@ async def respond_with_multipart_responder( try: await responder.write_to_consumer(multipart_consumer) + except ConsumerRequestedStopError as e: + logger.debug("Failed to write to consumer: %s %s", type(e), e) + # Unregister the producer, if it has one, so Twisted doesn't complain + if request.producer: + request.unregisterProducer() except Exception as e: - # The majority of the time this will be due to the client having gone - # away. Unfortunately, Twisted simply throws a generic exception at us - # in that case. logger.warning("Failed to write to consumer: %s %s", type(e), e) - # Unregister the producer, if it has one, so Twisted doesn't complain if request.producer: request.unregisterProducer() @@ -426,12 +427,13 @@ async def respond_with_responder( add_file_headers(request, media_type, file_size, upload_name) try: await responder.write_to_consumer(request) + except ConsumerRequestedStopError as e: + logger.debug("Failed to write to consumer: %s %s", type(e), e) + # Unregister the producer, if it has one, so Twisted doesn't complain + if request.producer: + request.unregisterProducer() except Exception as e: - # The majority of the time this will be due to the client having gone - # away. Unfortunately, Twisted simply throws a generic exception at us - # in that case. logger.warning("Failed to write to consumer: %s %s", type(e), e) - # Unregister the producer, if it has one, so Twisted doesn't complain if request.producer: request.unregisterProducer() @@ -674,6 +676,10 @@ def _parseparam(s: bytes) -> Generator[bytes, None, None]: s = s[end:] +class ConsumerRequestedStopError(Exception): + """A consumer asked us to stop producing""" + + @implementer(interfaces.IPushProducer) class ThreadedFileSender: """ @@ -751,7 +757,9 @@ class ThreadedFileSender: self.wakeup_event.set() if not self.deferred.called: - self.deferred.errback(Exception("Consumer asked us to stop producing")) + self.deferred.errback( + ConsumerRequestedStopError("Consumer asked us to stop producing") + ) async def start_read_loop(self) -> None: """This is the loop that drives reading/writing"""