diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
index 7e4ffe2719e4af2a9e56c9ee097ed6720f5c3906_bWVyY3VyaWFsL2h0dHBwZWVyLnB5..588f1e9a4d1665b8dc02ab409312f59d06414d02_bWVyY3VyaWFsL2h0dHBwZWVyLnB5 100644
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -405,5 +405,11 @@
         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') %
@@ -408,8 +414,6 @@
         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
index 7e4ffe2719e4af2a9e56c9ee097ed6720f5c3906_bWVyY3VyaWFsL2tlZXBhbGl2ZS5weQ==..588f1e9a4d1665b8dc02ab409312f59d06414d02_bWVyY3VyaWFsL2tlZXBhbGl2ZS5weQ== 100644
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -442,7 +442,10 @@
         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: