changeset 36994:d683c7367989

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
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 10 Mar 2018 23:58:01 -0500
parents b6a4881cec19
children ccc2d5f10421
files mercurial/util.py mercurial/wireproto.py
diffstat 2 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/util.py	Sat Mar 10 23:58:01 2018 -0500
@@ -715,11 +715,13 @@
     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.
@@ -727,6 +729,7 @@
         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:
--- a/mercurial/wireproto.py	Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/wireproto.py	Sat Mar 10 23:58:01 2018 -0500
@@ -1077,6 +1077,7 @@
                     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),