Skip to content

Commit 408ebf9

Browse files
richvdhphil-flex
authored andcommitted
Fix a bug which could cause incorrect 'cyclic dependency' error. (matrix-org#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: matrix-org#7169
1 parent 2f70034 commit 408ebf9

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

changelog.d/7178.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug which could cause incorrect 'cyclic dependency' error.

synapse/server.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -583,24 +583,22 @@ def _get(hs):
583583
try:
584584
builder = getattr(hs, "build_%s" % (depname))
585585
except AttributeError:
586-
builder = None
586+
raise NotImplementedError(
587+
"%s has no %s nor a builder for it" % (type(hs).__name__, depname)
588+
)
587589

588-
if builder:
589-
# Prevent cyclic dependencies from deadlocking
590-
if depname in hs._building:
591-
raise ValueError("Cyclic dependency while building %s" % (depname,))
592-
hs._building[depname] = 1
590+
# Prevent cyclic dependencies from deadlocking
591+
if depname in hs._building:
592+
raise ValueError("Cyclic dependency while building %s" % (depname,))
593593

594+
hs._building[depname] = 1
595+
try:
594596
dep = builder()
595597
setattr(hs, depname, dep)
596-
598+
finally:
597599
del hs._building[depname]
598600

599-
return dep
600-
601-
raise NotImplementedError(
602-
"%s has no %s nor a builder for it" % (type(hs).__name__, depname)
603-
)
601+
return dep
604602

605603
setattr(HomeServer, "get_%s" % (depname), _get)
606604

0 commit comments

Comments
 (0)