From 9cb1642f497a50596255859e5fd255104a1c7034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Tue, 26 Mar 2019 08:22:37 +0100 Subject: [PATCH] rest/media: Don't call finish in case of error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an exception occurs during the sending of data, the request doesn't needs a finishing, otherwise twisted complains `Producer was not unregistered for b'/_matrix/media/v1/thumbnail/…'`. Fixes #4933 --- synapse/rest/media/v1/_base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/synapse/rest/media/v1/_base.py b/synapse/rest/media/v1/_base.py index 953d89bd8203..90d69a74c267 100644 --- a/synapse/rest/media/v1/_base.py +++ b/synapse/rest/media/v1/_base.py @@ -185,13 +185,14 @@ def respond_with_responder(request, responder, media_type, file_size, upload_nam try: with responder: yield responder.write_to_consumer(request) + + finish_request(request) 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) - - finish_request(request) + if str(e) != "Consumer asked us to stop producing": + logger.warning("Failed to write to consumer: %s %s", type(e), e) class Responder(object):