Error cloning mercurial repository (http) after first install

I’m having troubles with getting mercuial to work via http.
I’ve installed latest phabricator (latest master at the moment i’m writing this post), php 7.2, nginx, mercurial 4.5 (tried 4.4 and 4.3 as well). I’ve made only basic setup to test mercurial support.
On clone operation I’m getting error 500. I’ve tried to investigate problem by myself.

Phabricator is launching following command:
'/usr/bin/hg' -R '/opt/phacility/repo/1/' serve --stdio

and writes to stdin following data:

And mercurial exits with exception after that:

** unknown exception encountered, please report by visiting
** Python 2.7.14 (default, Mar  3 2018, 13:51:37) [GCC 7.3.0]
** Mercurial Distributed SCM (version 4.5)
** Extensions loaded: 
Traceback (most recent call last):
  File "/usr/lib/python-exec/python2.7/hg", line 41, in <module>
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 88, in run
    status = (dispatch(req) or 0) & 255
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 183, in dispatch
    ret = _runcatch(req)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 324, in _runcatch
    return _callcatch(ui, _runcatchfunc)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 332, in _callcatch
    return scmutil.callcatch(ui, func)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 154, in callcatch
    return func()
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 314, in _runcatchfunc
    return _dispatch(req)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 918, in _dispatch
    cmdpats, cmdoptions)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 673, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 926, in _runcommand
    return cmdfunc()
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 915, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 1195, in check
    return func(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 4760, in serve
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 98, in serve_forever
    while self.serve_one():
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 117, in serve_one
    rsp = wireproto.dispatch(self.repo, self, cmd)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 585, in dispatch
    args = proto.getargs(spec)
  File "/usr/lib64/python2.7/site-packages/mercurial/", line 43, in getargs
    arg, l = argline.split()
ValueError: need more than 0 values to unpack

Any help appreciated.

Small notice: there is no HTTP_X_HGARG_… in this request and query string is: /source/test/&cmd=listkeys&namespace=bookmarks

I’ve found solution! In order for latest mercurial to work, you need this patch:

diff --git a/src/applications/diffusion/protocol/DiffusionMercurialWireProtocol.php b/src/applications/diffusion/protocol/DiffusionMercurialWireProtocol.php
index 251935a6d..b90c40842 100644
--- a/src/applications/diffusion/protocol/DiffusionMercurialWireProtocol.php
+++ b/src/applications/diffusion/protocol/DiffusionMercurialWireProtocol.php
@@ -126,6 +126,7 @@ final class DiffusionMercurialWireProtocol extends Phobject {
+    array_push($parts, 'httpheader=1024');
     return implode(' ', $parts);

Wow, this just saved me. I’m not sure why this isn’t in the repo already, but I was getting 500 errors for every pull/clone request after upgrading to hg 4.4.1, and this fixed it. no issues now.