Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix a bug which could cause incorrect 'cyclic dependency' error. (#7178)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
richvdh committed Mar 31, 2020
1 parent 7966a1c commit 62a7289
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.d/7178.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which could cause incorrect 'cyclic dependency' error.
22 changes: 10 additions & 12 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,24 +583,22 @@ def _get(hs):
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)

Expand Down

0 comments on commit 62a7289

Please sign in to comment.