From ef5273847c5b0a8c71d2071b8299434dd457b026 Mon Sep 17 00:00:00 2001 From: Sean Quah Date: Fri, 25 Feb 2022 19:27:31 +0000 Subject: [PATCH] Don't cancel `Deferred`s that readers or writers are waiting on --- synapse/util/async_helpers.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/synapse/util/async_helpers.py b/synapse/util/async_helpers.py index 6bb20dc3d115..05ae2170e637 100644 --- a/synapse/util/async_helpers.py +++ b/synapse/util/async_helpers.py @@ -513,9 +513,10 @@ async def _ctx_manager() -> AsyncIterator[None]: try: # Wait for the latest writer to finish. # May raise a `CancelledError` if the `Deferred` wrapping us is - # cancelled. + # cancelled. The `Deferred` we are waiting on must not be cancelled, + # since we do not own it. if curr_writer: - await make_deferred_yieldable(curr_writer) + await make_deferred_yieldable(stop_cancellation(curr_writer)) yield finally: with PreserveLoggingContext(): @@ -546,8 +547,9 @@ async def _ctx_manager() -> AsyncIterator[None]: try: # Wait for all current readers and the latest writer to finish. # May raise a `CancelledError` if the `Deferred` wrapping us is - # cancelled. - await make_deferred_yieldable(to_wait_on_defer) + # cancelled. The `Deferred`s we are waiting on must not be cancelled, + # since we do not own them. + await make_deferred_yieldable(stop_cancellation(to_wait_on_defer)) yield finally: