Patchwork D4053: [RFC]hgweb: garbage collect on every request in hgweb_mod too

login
register
mail settings
Submitter phabricator
Date Aug. 2, 2018, 3:58 p.m.
Message ID <fa8ec1dca0724d3fb4536ddeb4385476@localhost.localdomain>
Download mbox | patch
Permalink /patch/33112/
State Not Applicable
Headers show

Comments

phabricator - Aug. 2, 2018, 3:58 p.m.
pulkit updated this revision to Diff 9792.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4053?vs=9787&id=9792

REVISION DETAIL
  https://phab.mercurial-scm.org/D4053

AFFECTED FILES
  mercurial/hgweb/hgweb_mod.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -9,6 +9,7 @@ 
 from __future__ import absolute_import
 
 import contextlib
+import gc
 import os
 
 from .common import (
@@ -305,8 +306,19 @@ 
         with self._obtainrepo() as repo:
             profile = repo.ui.configbool('profiling', 'enabled')
             with profiling.profile(repo.ui, enabled=profile):
-                for r in self._runwsgi(req, res, repo):
-                    yield r
+                try:
+                    for r in self._runwsgi(req, res, repo):
+                        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, repo):
         rctx = requestcontext(self, repo, req, res)