mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-05 22:28:54 +01:00
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
This commit is contained in:
parent
7966a1cde9
commit
62a7289133
2 changed files with 11 additions and 12 deletions
1
changelog.d/7178.bugfix
Normal file
1
changelog.d/7178.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix a bug which could cause incorrect 'cyclic dependency' error.
|
|
@ -583,24 +583,22 @@ def _make_dependency_method(depname):
|
||||||
try:
|
try:
|
||||||
builder = getattr(hs, "build_%s" % (depname))
|
builder = getattr(hs, "build_%s" % (depname))
|
||||||
except AttributeError:
|
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
|
||||||
# Prevent cyclic dependencies from deadlocking
|
if depname in hs._building:
|
||||||
if depname in hs._building:
|
raise ValueError("Cyclic dependency while building %s" % (depname,))
|
||||||
raise ValueError("Cyclic dependency while building %s" % (depname,))
|
|
||||||
hs._building[depname] = 1
|
|
||||||
|
|
||||||
|
hs._building[depname] = 1
|
||||||
|
try:
|
||||||
dep = builder()
|
dep = builder()
|
||||||
setattr(hs, depname, dep)
|
setattr(hs, depname, dep)
|
||||||
|
finally:
|
||||||
del hs._building[depname]
|
del hs._building[depname]
|
||||||
|
|
||||||
return dep
|
return dep
|
||||||
|
|
||||||
raise NotImplementedError(
|
|
||||||
"%s has no %s nor a builder for it" % (type(hs).__name__, depname)
|
|
||||||
)
|
|
||||||
|
|
||||||
setattr(HomeServer, "get_%s" % (depname), _get)
|
setattr(HomeServer, "get_%s" % (depname), _get)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue