summary refs log tree commit diff
path: root/synapse/http/server.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-09-28 14:36:19 +0100
committerGitHub <noreply@github.com>2021-09-28 14:36:19 +0100
commit37bb93d1818eeda0d64c02cb772c8dee5596194f (patch)
treec4c390ba666bac1ff4a08c55ab93dcc77679809c /synapse/http/server.py
parentFixup changelog (diff)
downloadsynapse-37bb93d1818eeda0d64c02cb772c8dee5596194f.tar.xz
Fix exception responding to request that has been closed (#10932)
Introduced in #10905
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r--synapse/http/server.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 1a50305dcf..0df1bfbeef 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -561,9 +561,17 @@ class _ByteProducer:
         self._iterator = iterator
         self._paused = False
 
-        # Register the producer and start producing data.
-        self._request.registerProducer(self, True)
-        self.resumeProducing()
+        try:
+            self._request.registerProducer(self, True)
+        except RuntimeError as e:
+            logger.info("Connection disconnected before response was written: %r", e)
+
+            # We drop our references to data we'll not use.
+            self._request = None
+            self._iterator = iter(())
+        else:
+            # Start producing if `registerProducer` was successful
+            self.resumeProducing()
 
     def _send_data(self, data: List[bytes]) -> None:
         """