changeset 36851:31581528f242

debugwireproto: close the write end before consuming all available data And make it read all available data deterministically. Otherwise util.poll() may deadlock because both stdout and stderr could have no data. Spotted by the next patch which removes stderr from the fds.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 12 Mar 2018 22:47:33 +0900
parents ff541b8cdee0
children 14f70c44af6c
files mercurial/debugcommands.py tests/test-ssh-proto-unbundle.t tests/test-ssh-proto.t
diffstat 3 files changed, 39 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Fri Mar 09 15:57:16 2018 +0100
+++ b/mercurial/debugcommands.py	Mon Mar 12 22:47:33 2018 +0900
@@ -2690,7 +2690,8 @@
     readavailable
     -------------
 
-    Read all available data from the server.
+    Close the write end of the connection and read all available data from
+    the server.
 
     If the connection to the server encompasses multiple pipes, we poll both
     pipes and read available data.
@@ -2835,17 +2836,9 @@
         elif action == 'close':
             peer.close()
         elif action == 'readavailable':
-            fds = [stdout.fileno(), stderr.fileno()]
-            try:
-                act = util.poll(fds)
-            except NotImplementedError:
-                # non supported yet case, assume all have data.
-                act = fds
-
-            if stdout.fileno() in act:
-                util.readpipe(stdout)
-            if stderr.fileno() in act:
-                util.readpipe(stderr)
+            stdin.close()
+            stdout.read()
+            stderr.read()
         elif action == 'readline':
             stdout.readline()
         else:
--- a/tests/test-ssh-proto-unbundle.t	Fri Mar 09 15:57:16 2018 +0100
+++ b/tests/test-ssh-proto-unbundle.t	Mon Mar 12 22:47:33 2018 +0900
@@ -93,6 +93,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 115:
   e>     abort: incompatible Mercurial client; bundle2 required\n
   e>     (see https://www.mercurial-scm.org/wiki/IncompatibleClient)\n
@@ -143,6 +144,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 115:
   e>     abort: incompatible Mercurial client; bundle2 required\n
   e>     (see https://www.mercurial-scm.org/wiki/IncompatibleClient)\n
@@ -260,6 +262,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 196:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -316,6 +319,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 196:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -386,6 +390,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 218:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -443,6 +448,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 218:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -514,6 +520,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 202:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -570,6 +577,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 202:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -640,6 +648,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 206:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -697,6 +706,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 206:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -768,6 +778,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 232:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -827,6 +838,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 232:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -900,6 +912,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 193:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -956,6 +969,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 193:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1026,6 +1040,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 218:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1085,6 +1100,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 218:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1158,6 +1174,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 216:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1217,6 +1234,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 216:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1296,6 +1314,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 212:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1353,6 +1372,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 212:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1425,6 +1445,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 212:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1482,6 +1503,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 212:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1556,6 +1578,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 230:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1615,6 +1638,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 230:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1697,6 +1721,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 273:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1760,6 +1785,7 @@
   o> read(1) -> 1: 0
   result: 0
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 273:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1837,6 +1863,7 @@
   o> read(1) -> 1: 1
   result: 1
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 100:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1889,6 +1916,7 @@
   o> read(1) -> 1: 1
   result: 1
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 100:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -1967,6 +1995,7 @@
   o> read(1) -> 1: 1
   result: 1
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 152:
   e>     adding changesets\n
   e>     adding manifests\n
@@ -2023,6 +2052,7 @@
   o> read(1) -> 1: 1
   result: 1
   remote output: 
+  o> read(-1) -> 0: 
   e> read(-1) -> 152:
   e>     adding changesets\n
   e>     adding manifests\n
--- a/tests/test-ssh-proto.t	Fri Mar 09 15:57:16 2018 +0100
+++ b/tests/test-ssh-proto.t	Mon Mar 12 22:47:33 2018 +0900
@@ -1138,6 +1138,7 @@
   i>     hello\n
   o> readline() -> 1:
   o>     \n
+  o> read(-1) -> 0: 
   e> read(-1) -> 42:
   e>     cannot upgrade protocols multiple times\n
   e>     -\n
@@ -1229,6 +1230,7 @@
   i>     invalid\n
   o> readline() -> 1:
   o>     \n
+  o> read(-1) -> 0: 
   e> read(-1) -> 46:
   e>     malformed handshake protocol: missing hello\n
   e>     -\n
@@ -1248,6 +1250,7 @@
   i>     invalid\n
   o> readline() -> 1:
   o>     \n
+  o> read(-1) -> 0: 
   e> read(-1) -> 48:
   e>     malformed handshake protocol: missing between\n
   e>     -\n
@@ -1269,6 +1272,7 @@
   i>     invalid\n
   o> readline() -> 1:
   o>     \n
+  o> read(-1) -> 0: 
   e> read(-1) -> 49:
   e>     malformed handshake protocol: missing pairs 81\n
   e>     -\n