Rev 4885: Wrap the call to .write() to raise ConnectionReset on failure. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-client-reconnect-819604

John Arbash Meinel john at arbash-meinel.com
Wed Sep 28 14:33:27 UTC 2011


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

------------------------------------------------------------
revno: 4885
revision-id: john at arbash-meinel.com-20110928143314-3xaxy2h2g9agzsyr
parent: john at arbash-meinel.com-20110928142559-qp5pxasjovebzatk
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-client-reconnect-819604
timestamp: Wed 2011-09-28 16:33:14 +0200
message:
  Wrap the call to .write() to raise ConnectionReset on failure.
-------------- next part --------------
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2010-04-27 06:40:37 +0000
+++ b/bzrlib/smart/medium.py	2011-09-28 14:33:14 +0000
@@ -726,7 +726,13 @@
 
     def _accept_bytes(self, bytes):
         """See SmartClientStreamMedium.accept_bytes."""
-        osutils.until_no_eintr(self._writeable_pipe.write, bytes)
+        try:
+            osutils.until_no_eintr(self._writeable_pipe.write, bytes)
+        except IOError, e:
+            if e.errno in (errno.EINVAL, errno.EPIPE):
+                raise errors.ConnectionReset(
+                    "Error trying to write to subprocess:\n%s"
+                    % (e,))
         self._report_activity(len(bytes), 'write')
 
     def _flush(self):

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2011-09-28 14:25:59 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2011-09-28 14:33:14 +0000
@@ -184,8 +184,12 @@
         client_medium._accept_bytes('abc')
         self.assertEqual('abc', client_medium._read_bytes(3))
         p.wait()
-        # On win32 python2.6 we get IOError(EINVAL) trying to do this.
-        client_medium._accept_bytes('more')
+        # While writing to the underlying pipe,
+        #   Windows py2.6.6 we get IOError(EINVAL)
+        #   Lucid py2.6.5, we get IOError(EPIPE)
+        # In both cases, it should be wrapped to ConnectionReset
+        self.assertRaises(errors.ConnectionReset,
+                          client_medium._accept_bytes, 'more')
 
     def test_simple_pipes_client_disconnect_does_nothing(self):
         # calling disconnect does nothing.



More information about the bazaar-commits mailing list