Skip to content

Commit a5c700f

Browse files
committed
Reload metadata in-place
Metadata reloading was previously implemented by loading the metadata, then replacing references to the old metadata with the new metadata. A bug in the implementation caused the previous version of the metadata to be indirectly referenced by the new version of the metadata, resulting in a steady climb in memory usage. In fixing the memory leak, I have also changed how metadata is reloaded to avoid having to replace all existing references, which is prone to errors and could cause confusing behaviour.
1 parent 8b2c80c commit a5c700f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/saml2/entity.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,11 @@ def reload_metadata(self, metadata_conf):
218218
"""
219219
logger.debug("Loading new metadata")
220220
try:
221-
new_metadata = self.config.load_metadata(metadata_conf)
221+
self.metadata.reload(metadata_conf)
222222
except Exception as ex:
223223
logger.error("Loading metadata failed", exc_info=ex)
224224
return False
225225

226-
logger.debug("Applying new metadata to main config")
227-
( self.metadata, self.sec.metadata, self.config.metadata ) = [new_metadata]*3
228-
policy = getattr(self.config, "_%s_policy" % self.entity_type, None)
229-
if policy and policy.metadata_store:
230-
logger.debug("Applying new metadata to %s policy", self.entity_type)
231-
policy.metadata_store = self.metadata
232-
233-
logger.debug("Applying new metadata source_id")
234226
self.sourceid = self.metadata.construct_source_id()
235227

236228
return True

src/saml2/mdstore.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,15 @@ def load(self, *args, **kwargs):
11101110
_md.load()
11111111
self.metadata[key] = _md
11121112

1113+
def reload(self, spec):
1114+
old_metadata = self.metadata
1115+
self.metadata = {}
1116+
try:
1117+
self.imp(spec)
1118+
except Exception as e:
1119+
self.metadata = old_metadata
1120+
raise e
1121+
11131122
def imp(self, spec):
11141123
# This serves as a backwards compatibility
11151124
if type(spec) is dict:

0 commit comments

Comments
 (0)