summary refs log tree commit diff
path: root/synapse/crypto/keyring.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2019-07-19 17:57:00 +0100
committerRichard van der Hoff <richard@matrix.org>2019-07-19 17:57:00 +0100
commitdcca56babad3a42ac9967995f7e6f9db51e37353 (patch)
tree802272e73ace81c9d2d95405ebdc9a9448488705 /synapse/crypto/keyring.py
parentRefactor Keyring._start_key_lookups (diff)
downloadsynapse-dcca56babad3a42ac9967995f7e6f9db51e37353.tar.xz
Add a delay to key lookup lock release to fix stack overflow
A tactical call_later here should fix #5723
Diffstat (limited to 'synapse/crypto/keyring.py')
-rw-r--r--synapse/crypto/keyring.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/synapse/crypto/keyring.py b/synapse/crypto/keyring.py
index efa72dc5fc..e8bb420ad1 100644
--- a/synapse/crypto/keyring.py
+++ b/synapse/crypto/keyring.py
@@ -259,6 +259,10 @@ class Keyring(object):
 
             # When we've finished fetching all the keys for a given server_name,
             # drop the lock by resolving the deferred in key_downloads.
+            def drop_server_lock(server_name):
+                d = self.key_downloads.pop(server_name)
+                d.callback(None)
+
             def lookup_done(res, verify_request):
                 server_name = verify_request.server_name
                 server_requests = server_to_request_ids[server_name]
@@ -269,8 +273,10 @@ class Keyring(object):
                     with PreserveLoggingContext(ctx):
                         logger.debug("Releasing key lookup lock on %s", server_name)
 
-                    d = self.key_downloads.pop(server_name)
-                    d.callback(None)
+                    # ... but not immediately, as that can cause stack explosions if
+                    # we get a long queue of lookups.
+                    self.clock.call_later(0, drop_server_lock, server_name)
+
                 return res
 
             for verify_request in verify_requests: