diff -r ed4ebbb98ca0 -r b5bf3dd6ec5b mercurial/wireprotov2server.py --- a/mercurial/wireprotov2server.py Mon Oct 08 15:19:32 2018 -0700 +++ b/mercurial/wireprotov2server.py Mon Oct 08 17:24:28 2018 -0700 @@ -194,7 +194,7 @@ reactor = wireprotoframing.serverreactor(ui, deferoutput=True) seencommand = False - outstream = reactor.makeoutputstream() + outstream = None while True: frame = wireprotoframing.readframe(req.bodyfh) @@ -207,6 +207,11 @@ # Need more data before we can do anything. continue elif action == 'runcommand': + # Defer creating output stream because we need to wait for + # protocol settings frames so proper encoding can be applied. + if not outstream: + outstream = reactor.makeoutputstream() + sentoutput = _httpv2runcommand(ui, repo, req, res, authedperm, reqcommand, reactor, outstream, meta, issubsequent=seencommand)