summary refs log tree commit diff
path: root/synapse/http/client.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-04-22 16:34:35 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2021-04-22 16:34:35 +0100
commita31eb4a9fd1c6af6de0c5162d80736eae7bdaba6 (patch)
tree1fd39929c29ecd3836bda570dbf33cc4fe2a8b7d /synapse/http/client.py
parentMerge commit 'd34c6e127' into anoa/dinsic_release_1_31_0 (diff)
parentAdd an admin API endpoint to protect media. (#9086) (diff)
downloadsynapse-a31eb4a9fd1c6af6de0c5162d80736eae7bdaba6.tar.xz
Merge commit '3e4cdfe5d' into anoa/dinsic_release_1_31_0
Diffstat (limited to '')
-rw-r--r--synapse/http/client.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py

index 531232cf5a..4e5ef106a0 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py
@@ -764,14 +764,24 @@ class _ReadBodyWithMaxSizeProtocol(protocol.Protocol): self.max_size = max_size def dataReceived(self, data: bytes) -> None: + # If the deferred was called, bail early. + if self.deferred.called: + return + self.stream.write(data) self.length += len(data) + # The first time the maximum size is exceeded, error and cancel the + # connection. dataReceived might be called again if data was received + # in the meantime. if self.max_size is not None and self.length >= self.max_size: self.deferred.errback(BodyExceededMaxSize()) - self.deferred = defer.Deferred() self.transport.loseConnection() def connectionLost(self, reason: Failure) -> None: + # If the maximum size was already exceeded, there's nothing to do. + if self.deferred.called: + return + if reason.check(ResponseDone): self.deferred.callback(self.length) elif reason.check(PotentialDataLoss):