Skip to content
Snippets Groups Projects
Unverified Commit 62a72891 authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

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
parent 7966a1cd
No related branches found
No related tags found
No related merge requests found
Fix a bug which could cause incorrect 'cyclic dependency' error.
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment