Patchwork [1,of,2] httppeer: calculate total expected bytes correctly

login
register
mail settings
Submitter Anton Shestakov
Date Sept. 10, 2018, 5:49 a.m.
Message ID <f3293d747c49a77677fc.1536558563@neuro>
Download mbox | patch
Permalink /patch/34444/
State Accepted
Headers show

Comments

Anton Shestakov - Sept. 10, 2018, 5:49 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1536422227 -28800
#      Sat Sep 08 23:57:07 2018 +0800
# Node ID f3293d747c49a77677fcb00554eecb09fe5502cb
# Parent  83dd656586b14a06b1b7e0fa57ab2a801eab3da5
httppeer: calculate total expected bytes correctly

User-facing error messages that handled httplib.IncompleteRead errors in
Mercurial used to look like this:

  abort: HTTP request error (incomplete response; expected 3 bytes got 1)

But the errors that are being handled underneath the UI look like this:

  IncompleteRead(1 bytes read, 3 more expected)

I.e. the error actually counts total number of expected bytes minus bytes
already received.

Before, users could see weird messages like "expected 10 bytes got 10", while
in reality httplib expected 10 _more_ bytes (20 in total).
Yuya Nishihara - Sept. 10, 2018, 11:18 a.m.
On Mon, 10 Sep 2018 13:49:23 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1536422227 -28800
> #      Sat Sep 08 23:57:07 2018 +0800
> # Node ID f3293d747c49a77677fcb00554eecb09fe5502cb
> # Parent  83dd656586b14a06b1b7e0fa57ab2a801eab3da5
> httppeer: calculate total expected bytes correctly

Queued, thanks.

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -84,9 +84,10 @@  def _wraphttpresponse(resp):
             except httplib.IncompleteRead as e:
                 # e.expected is an integer if length known or None otherwise.
                 if e.expected:
+                    got = len(e.partial)
+                    total = e.expected + got
                     msg = _('HTTP request error (incomplete response; '
-                            'expected %d bytes got %d)') % (e.expected,
-                                                           len(e.partial))
+                            'expected %d bytes got %d)') % (total, got)
                 else:
                     msg = _('HTTP request error (incomplete response)')
 
diff --git a/tests/test-http-bad-server.t b/tests/test-http-bad-server.t
--- a/tests/test-http-bad-server.t
+++ b/tests/test-http-bad-server.t
@@ -275,7 +275,7 @@  Server sends an incomplete capabilities 
   $ cat hg.pid > $DAEMON_PIDS
 
   $ hg clone http://localhost:$HGPORT/ clone
-  abort: HTTP request error (incomplete response; expected 416 bytes got 20)
+  abort: HTTP request error (incomplete response; expected 436 bytes got 20)
   (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator)
   [255]
 
@@ -600,7 +600,7 @@  Server sends partial bundle2 header magi
 
   $ hg clone http://localhost:$HGPORT/ clone
   requesting all changes
-  abort: HTTP request error (incomplete response; expected 1 bytes got 3)
+  abort: HTTP request error (incomplete response; expected 4 bytes got 3)
   (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator)
   [255]
 
@@ -624,7 +624,7 @@  Server sends incomplete bundle2 stream p
 
   $ hg clone http://localhost:$HGPORT/ clone
   requesting all changes
-  abort: HTTP request error (incomplete response; expected 1 bytes got 3)
+  abort: HTTP request error (incomplete response; expected 4 bytes got 3)
   (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator)
   [255]
 
@@ -733,7 +733,7 @@  Server stops after bundle2 part payload 
   adding changesets
   transaction abort!
   rollback completed
-  abort: HTTP request error (incomplete response; expected 459 bytes got 7)
+  abort: HTTP request error (incomplete response; expected 466 bytes got 7)
   (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator)
   [255]
 
@@ -799,7 +799,7 @@  Server stops sending after 0 length payl
   added 1 changesets with 1 changes to 1 files
   transaction abort!
   rollback completed
-  abort: HTTP request error (incomplete response; expected 23 bytes got 9)
+  abort: HTTP request error (incomplete response; expected 32 bytes got 9)
   (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator)
   [255]