Rev 4912: We should refuse to retry on read for -Dnoretry as well. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-read-reconnect-819604

John Arbash Meinel john at arbash-meinel.com
Mon Oct 10 13:00:46 UTC 2011


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

------------------------------------------------------------
revno: 4912 [merge]
revision-id: john at arbash-meinel.com-20111010130028-qvl0xb9skvpe0bja
parent: john at arbash-meinel.com-20111010124228-y6a7wq52lqtgn4q5
parent: john at arbash-meinel.com-20111010125843-ntwjed4qrt2h9xaq
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-client-read-reconnect-819604
timestamp: Mon 2011-10-10 15:00:28 +0200
message:
  We should refuse to retry on read for -Dnoretry as well.
modified:
  bzrlib/help_topics/en/debug-flags.txt debugflags.txt-20090312050229-rdspqbqq4fzbjtpe-1
  bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
  bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
-------------- next part --------------
=== modified file 'bzrlib/help_topics/en/debug-flags.txt'
--- a/bzrlib/help_topics/en/debug-flags.txt	2010-01-05 04:30:07 +0000
+++ b/bzrlib/help_topics/en/debug-flags.txt	2011-10-10 12:49:14 +0000
@@ -24,6 +24,8 @@
 -Dindex           Trace major index operations.
 -Dknit            Trace knit operations.
 -Dlock            Trace when lockdir locks are taken or released.
+-Dnoretry         If a connection is reset, fail immediately rather than
+                  retrying the request.
 -Dprogress        Trace progress bar operations.
 -Dmerge           Emit information for debugging merges.
 -Dno_apport       Don't use apport to report crashes.

=== modified file 'bzrlib/smart/client.py'
--- a/bzrlib/smart/client.py	2011-10-10 12:39:57 +0000
+++ b/bzrlib/smart/client.py	2011-10-10 13:00:28 +0000
@@ -22,6 +22,7 @@
 import bzrlib
 from bzrlib.smart import message, protocol
 from bzrlib import (
+    debug,
     errors,
     hooks,
     trace,
@@ -155,7 +156,7 @@
 
     def _is_safe_to_send_twice(self):
         """Check if the current method is re-entrant safe."""
-        if self.body_stream is not None:
+        if self.body_stream is not None or 'noretry' in debug.debug_flags:
             # We can't restart a body stream that has already been consumed.
             return False
         request_type = _mod_request.request_handlers.get_info(self.method)
@@ -269,13 +270,14 @@
 
             # Connection is dead, so close our end of it.
             self.client._medium.reset()
-            if self.body_stream is not None:
+            if (('noretry' in debug.debug_flags)
+                or self.body_stream is not None):
                 # We can't restart a body_stream that has been partially
                 # consumed, so we don't retry.
                 raise
+            trace.warning('ConnectionReset calling %r, retrying'
+                          % (self.method,))
             trace.log_exception_quietly()
-            trace.warning('ConnectionReset calling %s, retrying'
-                          % (self.method,))
             encoder, response_handler = self._construct_protocol(
                 protocol_version)
             self._send_no_retry(encoder)

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2011-10-10 12:31:45 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2011-10-10 13:00:28 +0000
@@ -28,6 +28,7 @@
 import bzrlib
 from bzrlib import (
         bzrdir,
+        debug,
         errors,
         osutils,
         tests,
@@ -3418,6 +3419,15 @@
         self.assertEqual(('ok',), response)
         self.assertEqual('content\n', response_handler.read_body_bytes())
 
+    def test__call_noretry_get_bytes(self):
+        debug.debug_flags.add('noretry')
+        response = self.make_response(('ok',), 'content\n')
+        output, vendor, smart_client = self.make_client_with_failing_medium(
+            fail_at_write=False, response=response)
+        smart_request = client._SmartClientRequest(smart_client, 'get',
+            ('foo',))
+        self.assertRaises(errors.ConnectionReset, smart_request._call, 3)
+
     def test__send_no_retry_pipes(self):
         client_read, server_write = create_file_pipes()
         server_read, client_write = create_file_pipes()
@@ -3500,6 +3510,18 @@
             ],
             vendor.calls)
 
+    def test__send_disabled_retry(self):
+        debug.debug_flags.add('noretry')
+        output, vendor, smart_client = self.make_client_with_failing_medium()
+        smart_request = client._SmartClientRequest(smart_client, 'hello', ())
+        self.assertRaises(errors.ConnectionReset, smart_request._send, 3)
+        self.assertEqual(
+            [('connect_ssh', 'a user', 'a pass', 'a host', 'a port',
+              ['bzr', 'serve', '--inet', '--directory=/', '--allow-writes']),
+             ('close',),
+            ],
+            vendor.calls)
+
 
 class LengthPrefixedBodyDecoder(tests.TestCase):
 



More information about the bazaar-commits mailing list