[PATCH V2] wireproto: explicitly flush stdio to prevent stalls on Windows

Matt Harbison mharbison72 at gmail.com
Sun Mar 11 19:51:24 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1520744281 18000
#      Sat Mar 10 23:58:01 2018 -0500
# Node ID 6c6b10b5d5bd617a01942974928b8b9c59eddb4a
# Parent  963b4223d14fa419df2a82fbe47cd55075707b6a
wireproto: explicitly flush stdio to prevent stalls on Windows

This is the key to fixing the hangs on Windows in D2720[1].  I put flushes in a
bunch of other places that didn't help, but I suspect that's more a lack of test
coverage than anything else.

Chasing down stuff like this is pretty painful.  I'm wondering if we can put a
proxy around sys.stderr (and sys.stdout?) on Windows (only when daemonized?)
that will flush on every write (or at least every write with a '\n').

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-March/113352.html

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -716,11 +716,13 @@ class fileobjectobserver(object):
     def _writedata(self, data):
         if not self.logdata:
             self.fh.write('\n')
+            self.fh.flush()
             return
 
         # Simple case writes all data on a single line.
         if b'\n' not in data:
             self.fh.write(': %s\n' % escapedata(data))
+            self.fh.flush()
             return
 
         # Data with newlines is written to multiple lines.
@@ -728,6 +730,7 @@ class fileobjectobserver(object):
         lines = data.splitlines(True)
         for line in lines:
             self.fh.write('%s>     %s\n' % (self.name, escapedata(line)))
+        self.fh.flush()
 
     def read(self, res, size=-1):
         if not self.reads:
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -1069,6 +1069,7 @@ def unbundle(repo, proto, heads):
                     util.stderr.write("abort: %s\n" % exc)
                     if exc.hint is not None:
                         util.stderr.write("(%s)\n" % exc.hint)
+                    util.stderr.flush()
                     return pushres(0, output.getvalue() if output else '')
                 except error.PushRaced:
                     return pusherr(pycompat.bytestr(exc),


More information about the Mercurial-devel mailing list