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

Commit e72b671

Browse files
author
Sean Quah
committed
Always call .finish()
1 parent bb24948 commit e72b671

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

synapse/http/matrixfederationclient.py

+11
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ async def _handle_response(
225225
if max_response_size is None:
226226
max_response_size = MAX_RESPONSE_SIZE
227227

228+
finished = False
228229
try:
229230
check_content_type_is(response.headers, parser.CONTENT_TYPE)
230231

@@ -233,6 +234,7 @@ async def _handle_response(
233234

234235
length = await make_deferred_yieldable(d)
235236

237+
finished = True
236238
value = parser.finish()
237239
except BodyExceededMaxSize as e:
238240
# The response was too big.
@@ -283,6 +285,15 @@ async def _handle_response(
283285
e,
284286
)
285287
raise
288+
finally:
289+
if not finished:
290+
# There was an exception and we didn't `finish()` the parse.
291+
# Let the parser know that it can free up any resources.
292+
try:
293+
parser.finish()
294+
except Exception:
295+
# Ignore any additional exceptions.
296+
pass
286297

287298
time_taken_secs = reactor.seconds() - start_ms / 1000
288299

0 commit comments

Comments
 (0)