Patchwork [STABLE] http: work around custom http client classes that refuse extra attrs

login
register
mail settings
Submitter Augie Fackler
Date Oct. 29, 2018, 8:28 p.m.
Message ID <588f1e9a4d1665b8dc02.1540844883@cardolan.pit.corp.google.com>
Download mbox | patch
Permalink /patch/36284/
State Accepted
Headers show

Comments

Augie Fackler - Oct. 29, 2018, 8:28 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1540844622 14400
#      Mon Oct 29 16:23:42 2018 -0400
# Branch stable
# Node ID 588f1e9a4d1665b8dc02ab409312f59d06414d02
# Parent  7e4ffe2719e4af2a9e56c9ee097ed6720f5c3906
http: work around custom http client classes that refuse extra attrs

I have no idea what is going on with our custom http client code at Google,
but it chokes on these extra attributes we're tucking on http clients. Since
it feels more than a little wrong to just stuff extra data on a client, let's
degrade gracefully when the client class refuses the attributes.
Yuya Nishihara - Oct. 30, 2018, 11:42 a.m.
On Mon, 29 Oct 2018 16:28:03 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1540844622 14400
> #      Mon Oct 29 16:23:42 2018 -0400
> # Branch stable
> # Node ID 588f1e9a4d1665b8dc02ab409312f59d06414d02
> # Parent  7e4ffe2719e4af2a9e56c9ee097ed6720f5c3906
> http: work around custom http client classes that refuse extra attrs

Seems fine. Queued for stable, thanks.

> --- a/mercurial/keepalive.py
> +++ b/mercurial/keepalive.py
> @@ -442,7 +442,10 @@ class HTTPResponse(httplib.HTTPResponse)
>          data = self._raw_read(amt)
>  
>          self.receivedbytescount += len(data)
> -        self._connection.receivedbytescount += len(data)
> +        try:
> +            self._connection.receivedbytescount += len(data)
> +        except AttributeError:
> +            pass

There are two more self._connection.receivedbytescount in keepalive.py.

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -405,11 +405,15 @@  class httppeer(wireprotov1peer.wirepeer)
         return True
 
     def close(self):
+        try:
+            reqs, sent, recv = (self._urlopener.requestscount,
+                                self._urlopener.sentbytescount,
+                                self._urlopener.receivedbytescount)
+        except AttributeError:
+            return
         self.ui.note(_('(sent %d HTTP requests and %d bytes; '
                        'received %d bytes in responses)\n') %
-                     (self._urlopener.requestscount,
-                      self._urlopener.sentbytescount,
-                      self._urlopener.receivedbytescount))
+                     (reqs, sent, recv))
 
     # End of ipeerconnection interface.
 
diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -442,7 +442,10 @@  class HTTPResponse(httplib.HTTPResponse)
         data = self._raw_read(amt)
 
         self.receivedbytescount += len(data)
-        self._connection.receivedbytescount += len(data)
+        try:
+            self._connection.receivedbytescount += len(data)
+        except AttributeError:
+            pass
         try:
             self._handler.parent.receivedbytescount += len(data)
         except AttributeError: