summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-03-31 13:09:16 +0100
committerGitHub <noreply@github.com>2020-03-31 13:09:16 +0100
commit62a7289133840b4f4a55844b4f24ec664c3d917b (patch)
tree7a803a10f87f12b99e50cb8e6c2f16efc9d561eb /synapse
parentRewrite prune_old_outbound_device_pokes for efficiency (#7159) (diff)
downloadsynapse-62a7289133840b4f4a55844b4f24ec664c3d917b.tar.xz
Fix a bug which could cause incorrect 'cyclic dependency' error. (#7178)
If there was an exception setting up one of the attributes of the Homeserver
god object, then future attempts to fetch that attribute would raise a
confusing "Cyclic dependency" error. Let's make sure that we clear the
`building` flag so that we just get the original exception.

Ref: #7169
Diffstat (limited to '')
-rw-r--r--synapse/server.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/synapse/server.py b/synapse/server.py
index cd86475d6b..9228e1c892 100644
--- a/synapse/server.py
+++ b/synapse/server.py
@@ -583,24 +583,22 @@ def _make_dependency_method(depname):
         try:
             builder = getattr(hs, "build_%s" % (depname))
         except AttributeError:
-            builder = None
+            raise NotImplementedError(
+                "%s has no %s nor a builder for it" % (type(hs).__name__, depname)
+            )
 
-        if builder:
-            # Prevent cyclic dependencies from deadlocking
-            if depname in hs._building:
-                raise ValueError("Cyclic dependency while building %s" % (depname,))
-            hs._building[depname] = 1
+        # Prevent cyclic dependencies from deadlocking
+        if depname in hs._building:
+            raise ValueError("Cyclic dependency while building %s" % (depname,))
 
+        hs._building[depname] = 1
+        try:
             dep = builder()
             setattr(hs, depname, dep)
-
+        finally:
             del hs._building[depname]
 
-            return dep
-
-        raise NotImplementedError(
-            "%s has no %s nor a builder for it" % (type(hs).__name__, depname)
-        )
+        return dep
 
     setattr(HomeServer, "get_%s" % (depname), _get)