Rev 4893: Start trying to reconnect to the server if we get a ConnectionReset during the transmission. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604

John Arbash Meinel john at arbash-meinel.com
Mon Oct 3 11:44:48 UTC 2011


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604

------------------------------------------------------------
revno: 4893
revision-id: john at arbash-meinel.com-20111003114428-uo8fz6damw4tle45
parent: john at arbash-meinel.com-20111003093255-w50xg5fvccjrba2v
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-client-reconnect-819604
timestamp: Mon 2011-10-03 13:44:28 +0200
message:
  Start trying to reconnect to the server if we get a ConnectionReset during the transmission.
-------------- next part --------------
=== modified file 'bzrlib/smart/client.py'
--- a/bzrlib/smart/client.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/smart/client.py	2011-10-03 11:44:28 +0000
@@ -20,6 +20,7 @@
 from bzrlib import (
     errors,
     hooks,
+    trace,
     )
 
 
@@ -39,8 +40,8 @@
     def __repr__(self):
         return '%s(%r)' % (self.__class__.__name__, self._medium)
 
-    def _send_request(self, protocol_version, method, args, body=None,
-                      readv_body=None, body_stream=None):
+    def _send_request_no_retry(self, protocol_version, method, args, body=None,
+                               readv_body=None, body_stream=None):
         encoder, response_handler = self._construct_protocol(
             protocol_version)
         encoder.set_headers(self._headers)
@@ -63,6 +64,23 @@
             encoder.call(method, *args)
         return response_handler
 
+    def _send_request(self, protocol_version, method, args, body=None,
+                      readv_body=None, body_stream=None):
+        try:
+            response_handler = self._send_request_no_retry(protocol_version,
+                method, args, body=None, readv_body=None, body_stream=None)
+        except errors.ConnectionReset, e:
+            # If we fail during the _send_request_no_retry phase, then we can
+            # be confident that the server did not get our request, because we
+            # haven't started waiting for the reply yet. So try the request
+            # again. We only issue a single retry, because if the connection
+            # really is down, there is no reason to loop endlessly.
+            trace.log_exception_quietly()
+            trace.warning('ConnectionReset calling %s, retrying' % (method,))
+            response_handler = self._send_request_no_retry(protocol_version,
+                method, args, body=None, readv_body=None, body_stream=None)
+        return response_handler
+
     def _run_call_hooks(self, method, args, body, readv_body):
         if not _SmartClient.hooks['call']:
             return



More information about the bazaar-commits mailing list