# HG changeset patch
# User Matt Harbison <matt_harbi...@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').


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.flush()
         # 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()
         # 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),
Mercurial-devel mailing list

Reply via email to