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

Fix a bug which could cause incorrect 'cyclic dependency' error. #7178

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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