hgweb: garbage collect on every request
There appears to be a cycle in localrepository or hgweb that
is preventing repositories from being garbage collected when
hgwebdir dispatches to hgweb. Every request creates a new
repository instance and then leaks that object and other referenced
objects. A periodic GC to find cycles will eventually collect the
old repositories. But these don't run reliably and rapid requests
to hgwebdir can result in rapidly increasing memory consumption.
With the Firefox repository, repeated requests to raw-file URLs
leak ~100 MB per hgwebdir request (most of this appears to be
cached manifest data structures). WSGI processes quickly grow
to >1 GB RSS.
Breaking the cycles in localrepository is going to be a bit of
work.
Because we know that hgwebdir leaks localrepository instances, let's
put a band aid on the problem in the form of an explicit gc.collect()
on every hgwebdir request.
As the inline comment states, ideally we'd do this in a finally
block for the current request iff it dispatches to hgweb. But
_runwsgi() returns an explicit value. We need the finally to run
after generator exhaustion. So we'd need to refactor _runwsgi()
to "yield" instead of "return." That's too much change for a patch
to stable. So we implement this hack one function above and run
it on every request.
The performance impact of this change should be minimal. Any
impact should be offset by benefits from not having hgwebdir
processes leak memory.
amend: abort if unresolved merge conflicts found (
issue5805)
It was checked by repo.commit() before
e8a7c1a0565a "cmdutil: remove the
redundant commit during amend."
debugwireproto: close the write end before consuming all available data
And make it read all available data deterministically. Otherwise util.poll()
may deadlock because both stdout and stderr could have no data.
Spotted by the next patch which removes stderr from the fds.
graft: check for missing revision first before scanning working copy
Differential Revision: https://phab.mercurial-scm.org/D2753
hook: ensure stderr is flushed when an exception is raised, for test stability
Windows has had issues with output order in test-ssh-proto-unbundle.t[1] since
it was created a few weeks ago. Each of the problems occurred when an exception
was thrown out of the hook.
Now the only thing blocking D2720 is the fact that the "abort: ..." lines on
stderr are totally AWOL. I have no idea where there are.
[1] https://buildbot.mercurial-scm.org/builders/Win7%20x86_64%20hg%20tests/builds/541/steps/run-tests.py%20%28python%202.7.13%29/logs/stdio
wireproto: raise ProgrammingError instead of Abort
This isn't a user-facing error and can only be caused by bad
Python code.
Thanks to Yuya for spotting this.
Differential Revision: https://phab.mercurial-scm.org/D2777
py3: open patch file in binary mode and convert eol manually
Here we don't introduce a reader wrapper since it wouldn't be easy to make
read(n) handle partial data and length correctly.