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

Commit e140a7d

Browse files
committed
Remove a reference cycle
1 parent 7afb5e0 commit e140a7d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

synapse/metrics/background_process_metrics.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,15 @@ def __init__(self, name: str, instance_id: Optional[Union[int, str]] = None):
322322
if instance_id is None:
323323
instance_id = id(self)
324324
super().__init__("%s-%s" % (name, instance_id))
325-
self._proc = _BackgroundProcess(name, self)
325+
self._proc: Optional[_BackgroundProcess] = _BackgroundProcess(name, self)
326326

327327
def start(self, rusage: "Optional[resource.struct_rusage]") -> None:
328328
"""Log context has started running (again)."""
329329

330330
super().start(rusage)
331331

332+
assert self._proc is not None
333+
332334
# We've become active again so we make sure we're in the list of active
333335
# procs. (Note that "start" here means we've become active, as opposed
334336
# to starting for the first time.)
@@ -345,10 +347,15 @@ def __exit__(
345347

346348
super().__exit__(type, value, traceback)
347349

350+
assert self._proc is not None
351+
348352
# The background process has finished. We explicitly remove and manually
349353
# update the metrics here so that if nothing is scraping metrics the set
350354
# doesn't infinitely grow.
351355
with _bg_metrics_lock:
352356
_background_processes_active_since_last_scrape.discard(self._proc)
353357

354358
self._proc.update_metrics()
359+
360+
# Set proc to None to break the reference cycle.
361+
self._proc = None

0 commit comments

Comments
 (0)