mercurial/hgweb/hgwebdir_mod.py
changeset 36978 c479692690ef
parent 36920 6ff6e1d6b5b8
parent 36845 ff2370a70fe8
child 36989 de117f579431
--- a/mercurial/hgweb/hgwebdir_mod.py	Fri Mar 16 12:10:15 2018 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sat Mar 17 21:46:17 2018 -0400
@@ -8,6 +8,7 @@
 
 from __future__ import absolute_import
 
+import gc
 import os
 import time
 
@@ -357,8 +358,18 @@
     def run_wsgi(self, req, res):
         profile = self.ui.configbool('profiling', 'enabled')
         with profiling.profile(self.ui, enabled=profile):
-            for r in self._runwsgi(req, res):
-                yield r
+            try:
+                for r in self._runwsgi(req, res):
+                    yield r
+            finally:
+                # There are known cycles in localrepository that prevent
+                # those objects (and tons of held references) from being
+                # collected through normal refcounting. We mitigate those
+                # leaks by performing an explicit GC on every request.
+                # TODO remove this once leaks are fixed.
+                # TODO only run this on requests that create localrepository
+                # instances instead of every request.
+                gc.collect()
 
     def _runwsgi(self, req, res):
         try: