Patchwork [2,of,3] sshserver: do setbinary() by caller (API)

login
register
mail settings
Submitter Yuya Nishihara
Date May 7, 2018, 1:11 p.m.
Message ID <ea801aa5d559e37f68fb.1525698683@mimosa>
Download mbox | patch
Permalink /patch/31300/
State Accepted
Headers show

Comments

Yuya Nishihara - May 7, 2018, 1:11 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521963324 -32400
#      Sun Mar 25 16:35:24 2018 +0900
# Node ID ea801aa5d559e37f68fb9bdda47dec6e58abcb88
# Parent  2be95f3cc4f8a4b59f7c50af093ea033d1d09c5e
sshserver: do setbinary() by caller (API)

In most cases, stdio should be set to binary mode by the dispatcher, so
the sshserver does not have to take care of that. The only exception was
hg-ssh, which is fixed by this patch.

.. api::

   ``sshserver()`` no longer sets stdin and stdout to binary mode.
Matt Harbison - May 12, 2018, 9:49 p.m.
On Mon, 07 May 2018 09:11:23 -0400, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1521963324 -32400
> #      Sun Mar 25 16:35:24 2018 +0900
> # Node ID ea801aa5d559e37f68fb9bdda47dec6e58abcb88
> # Parent  2be95f3cc4f8a4b59f7c50af093ea033d1d09c5e
> sshserver: do setbinary() by caller (API)

This seems to be the cause of the recent odd test failures on Windows.   
I'm not in front of the testbot machine, but test-http-branchmap.t is  
hanging on my laptop here:

SALT1526160986 87 0
+ hg -R b ci -m baz
+ echo SALT1526160986 88 0
SALT1526160986 88 0
+ hg push -R b -e '"c:/Python27/python.exe" oldhg' ssh://dummy/ --encoding  
latin1

For whatever reason, -t30 doesn't cause the test to timeout.  If I kill  
the python.exe doing the push, the test passes(!), and the server shuts  
down properly.  I suspect a flush is missing, but I've no idea where.
Yuya Nishihara - May 13, 2018, 2:15 a.m.
On Sat, 12 May 2018 17:49:30 -0400, Matt Harbison wrote:
> On Mon, 07 May 2018 09:11:23 -0400, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1521963324 -32400
> > #      Sun Mar 25 16:35:24 2018 +0900
> > # Node ID ea801aa5d559e37f68fb9bdda47dec6e58abcb88
> > # Parent  2be95f3cc4f8a4b59f7c50af093ea033d1d09c5e
> > sshserver: do setbinary() by caller (API)
> 
> This seems to be the cause of the recent odd test failures on Windows.   
> I'm not in front of the testbot machine, but test-http-branchmap.t is  
> hanging on my laptop here:
> 
> SALT1526160986 87 0
> + hg -R b ci -m baz
> + echo SALT1526160986 88 0
> SALT1526160986 88 0
> + hg push -R b -e '"c:/Python27/python.exe" oldhg' ssh://dummy/ --encoding  
> latin1

Fixed. I'll send the patches shortly.

> For whatever reason, -t30 doesn't cause the test to timeout.  If I kill  
> the python.exe doing the push, the test passes(!), and the server shuts  
> down properly.  I suspect a flush is missing, but I've no idea where.

Some blocking I/O can't be interrupted on Windows.

Patch

diff --git a/contrib/hg-ssh b/contrib/hg-ssh
--- a/contrib/hg-ssh
+++ b/contrib/hg-ssh
@@ -43,6 +43,9 @@  from mercurial import (
 )
 
 def main():
+    # Prevent insertion/deletion of CRs
+    dispatch.initstdio()
+
     cwd = os.getcwd()
     readonly = False
     args = sys.argv[1:]
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -83,7 +83,7 @@  class request(object):
 
 def run():
     "run the command in sys.argv"
-    _initstdio()
+    initstdio()
     req = request(pycompat.sysargv[1:])
     err = None
     try:
@@ -112,7 +112,7 @@  def run():
     sys.exit(status & 255)
 
 if pycompat.ispy3:
-    def _initstdio():
+    def initstdio():
         pass
 
     def _silencestdio():
@@ -132,7 +132,7 @@  if pycompat.ispy3:
             except IOError:
                 pass
 else:
-    def _initstdio():
+    def initstdio():
         for fp in (sys.stdin, sys.stdout, sys.stderr):
             procutil.setbinary(fp)
 
diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -798,10 +798,6 @@  class sshserver(object):
         hook.redirect(True)
         ui.fout = repo.ui.fout = ui.ferr
 
-        # Prevent insertion/deletion of CRs
-        procutil.setbinary(self._fin)
-        procutil.setbinary(self._fout)
-
     def serve_forever(self):
         self.serveuntil(threading.Event())
         sys.exit(0)