# HG changeset patch # User Marcin Kuzminski # Date 2017-07-29 00:04:23 # Node ID 8784eaf09eccb132dc1ebdc90473d1a7689cc755 # Parent 55f1a7349a7892ad7b69fd610a7d96471b80d8ab Mercurial: fix stream ehxaustion problem. - webob odd implementation consumes the iterator. - this is a workardound fix to allows sending headers in first chunk, and rest of the stream later on. diff --git a/vcsserver/scm_app.py b/vcsserver/scm_app.py --- a/vcsserver/scm_app.py +++ b/vcsserver/scm_app.py @@ -17,6 +17,7 @@ import os import logging +import itertools import mercurial import mercurial.error @@ -67,8 +68,27 @@ class HgWeb(mercurial.hgweb.hgweb_mod.hg """Unused function so raise an exception if accidentally called.""" raise NotImplementedError - def run_wsgi(self, req): - """Check the request has a valid command, failing fast otherwise.""" + def __call__(self, environ, start_response): + """Run the WSGI application. + + This may be called by multiple threads. + """ + req = mercurial.hgweb.request.wsgirequest(environ, start_response) + gen = self.run_wsgi(req) + + first_chunk = None + + try: + data = gen.next() + def first_chunk(): yield data + except StopIteration: + pass + + if first_chunk: + return itertools.chain(first_chunk(), gen) + return gen + + def _runwsgi(self, req, repo): cmd = req.form.get('cmd', [''])[0] if not mercurial.hgweb.protocol.iscmd(cmd): req.respond( @@ -78,7 +98,7 @@ class HgWeb(mercurial.hgweb.hgweb_mod.hg ) return [''] - return super(HgWeb, self).run_wsgi(req) + return super(HgWeb, self)._runwsgi(req, repo) def make_hg_ui_from_config(repo_config):