Fix exception responding to request that has been closed (#10932)

Introduced in #10905
This commit is contained in:
Erik Johnston 2021-09-28 14:36:19 +01:00 committed by GitHub
parent 2b9d174791
commit 37bb93d181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -0,0 +1 @@
Speed up responding with large JSON objects to requests.

View file

@ -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:
"""