Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix exception responding to request that has been closed (#10932)
Browse files Browse the repository at this point in the history
Introduced in #10905
  • Loading branch information
erikjohnston authored Sep 28, 2021
1 parent 2b9d174 commit 37bb93d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/10932.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speed up responding with large JSON objects to requests.
14 changes: 11 additions & 3 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,17 @@ def __init__(
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:
"""
Expand Down

0 comments on commit 37bb93d

Please sign in to comment.