summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorSean Quah <8349537+squahtx@users.noreply.github.com>2022-03-01 15:27:15 +0000
committerGitHub <noreply@github.com>2022-03-01 15:27:15 +0000
commit4d6b6c17c860a6ef258e513d841dbda6ea151cbd (patch)
tree1ab3f9180e5b6f1931d442536dc63559a1950420 /synapse
parentAdd module callbacks called for reacting to deactivation status change and pr... (diff)
downloadsynapse-4d6b6c17c860a6ef258e513d841dbda6ea151cbd.tar.xz
Fix rare error in `ReadWriteLock` when writers complete immediately (#12105)
Signed-off-by: Sean Quah <seanq@element.io>
Diffstat (limited to 'synapse')
-rw-r--r--synapse/util/async_helpers.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/synapse/util/async_helpers.py b/synapse/util/async_helpers.py
index 81320b8972..60c03a66fd 100644
--- a/synapse/util/async_helpers.py
+++ b/synapse/util/async_helpers.py
@@ -555,7 +555,10 @@ class ReadWriteLock:
             finally:
                 with PreserveLoggingContext():
                     new_defer.callback(None)
-                if self.key_to_current_writer[key] == new_defer:
+                # `self.key_to_current_writer[key]` may be missing if there was another
+                # writer waiting for us and it completed entirely within the
+                # `new_defer.callback()` call above.
+                if self.key_to_current_writer.get(key) == new_defer:
                     self.key_to_current_writer.pop(key)
 
         return _ctx_manager()