Rev 6511: (jameinel) Treat socket.error(EPIPE) as a ConnectionReset (bug #1047325) so in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/
Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Sep 11 09:09:09 UTC 2012
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/
------------------------------------------------------------
revno: 6511 [merge]
revision-id: pqm at pqm.ubuntu.com-20120911090908-1xx05ree9c58y4in
parent: pqm at pqm.ubuntu.com-20120911075707-gyi8ss0rkgprg3h2
parent: john at arbash-meinel.com-20120911083914-j35o15f848xkl34n
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Tue 2012-09-11 09:09:08 +0000
message:
(jameinel) Treat socket.error(EPIPE) as a ConnectionReset (bug #1047325) so
that clients will properly reconnect. (John A Meinel)
modified:
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/smart/medium.py medium.py-20061103051856-rgu2huy59fkz902q-1
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2012-09-11 07:26:51 +0000
+++ b/bzrlib/osutils.py 2012-09-11 08:39:14 +0000
@@ -2064,7 +2064,7 @@
# data at once.
MAX_SOCKET_CHUNK = 64 * 1024
-_end_of_stream_errors = [errno.ECONNRESET]
+_end_of_stream_errors = [errno.ECONNRESET, errno.EPIPE, errno.EINVAL]
for _eno in ['WSAECONNRESET', 'WSAECONNABORTED']:
_eno = getattr(errno, _eno, None)
if _eno is not None:
@@ -2136,7 +2136,10 @@
while sent_total < byte_count:
try:
sent = sock.send(buffer(bytes, sent_total, MAX_SOCKET_CHUNK))
- except socket.error, e:
+ except (socket.error, IOError), e:
+ if e.args[0] in _end_of_stream_errors:
+ raise errors.ConnectionReset(
+ "Error trying to write to socket", e)
if e.args[0] != errno.EINTR:
raise
else:
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py 2011-12-24 09:59:02 +0000
+++ b/bzrlib/smart/medium.py 2012-09-10 11:50:34 +0000
@@ -910,7 +910,7 @@
except IOError, e:
if e.errno in (errno.EINVAL, errno.EPIPE):
raise errors.ConnectionReset(
- "Error trying to write to subprocess:\n%s" % (e,))
+ "Error trying to write to subprocess", e)
raise
self._report_activity(len(bytes), 'write')
@@ -1043,7 +1043,7 @@
class SmartClientSocketMedium(SmartClientStreamMedium):
"""A client medium using a socket.
-
+
This class isn't usable directly. Use one of its subclasses instead.
"""
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2012-09-11 07:26:51 +0000
+++ b/bzrlib/tests/test_osutils.py 2012-09-11 08:39:14 +0000
@@ -819,9 +819,26 @@
self.assertEqual(None, osutils.safe_file_id(None))
-
class TestSendAll(tests.TestCase):
+ def test_send_with_disconnected_socket(self):
+ class DisconnectedSocket(object):
+ def __init__(self, err):
+ self.err = err
+ def send(self, content):
+ raise self.err
+ def close(self):
+ pass
+ # All of these should be treated as ConnectionReset
+ errs = []
+ for err_cls in (IOError, socket.error):
+ for errnum in osutils._end_of_stream_errors:
+ errs.append(err_cls(errnum))
+ for err in errs:
+ sock = DisconnectedSocket(err)
+ self.assertRaises(errors.ConnectionReset,
+ osutils.send_all, sock, 'some more content')
+
def test_send_with_no_progress(self):
# See https://bugs.launchpad.net/bzr/+bug/1047309
# It seems that paramiko can get into a state where it doesn't error,
More information about the bazaar-commits
mailing list