Rev 6511: simplify the fix. Sending 0 bytes seems to always indicate that we have a closed connection. in http://bazaar.launchpad.net/~jameinel/bzr/2.5-unending-sendall-1047309
John Arbash Meinel
john at arbash-meinel.com
Tue Sep 11 07:27:05 UTC 2012
At http://bazaar.launchpad.net/~jameinel/bzr/2.5-unending-sendall-1047309
------------------------------------------------------------
revno: 6511
revision-id: john at arbash-meinel.com-20120911072651-0rys0d8a06xks71u
parent: john at arbash-meinel.com-20120907131502-q1t9i715sun447di
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-unending-sendall-1047309
timestamp: Tue 2012-09-11 11:26:51 +0400
message:
simplify the fix. Sending 0 bytes seems to always indicate that we have a closed connection.
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2012-09-07 13:15:02 +0000
+++ b/bzrlib/osutils.py 2012-09-11 07:26:51 +0000
@@ -2118,12 +2118,6 @@
return b
-# Consider making this configurable, but right now that seems very much YAGNI
-# This is how many 0's we can get in-a-row. If we manage to send some data
-# after a while, this number gets reset.
-_max_no_content_sends = 3
-
-
def send_all(sock, bytes, report_activity=None):
"""Send all bytes on a socket.
@@ -2138,7 +2132,6 @@
Transport._report_activity
"""
sent_total = 0
- no_content_count = 0
byte_count = len(bytes)
while sent_total < byte_count:
try:
@@ -2148,13 +2141,8 @@
raise
else:
if sent == 0:
- no_content_count += 1
- if no_content_count > _max_no_content_sends:
- raise IOError(errno.ECONNRESET,
- 'Sending to %s returned 0 bytes sent %d times in a row'
- % (sock, no_content_count))
- else:
- no_content_count = 0
+ raise errors.ConnectionReset('Sending to %s returned 0 bytes'
+ % (sock,))
sent_total += sent
if report_activity is not None:
report_activity(sent, 'write')
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2012-09-07 13:15:02 +0000
+++ b/bzrlib/tests/test_osutils.py 2012-09-11 07:26:51 +0000
@@ -836,25 +836,9 @@
raise RuntimeError('too many calls')
return 0
sock = NoSendingSocket()
- self.assertRaises(IOError, osutils.send_all, sock, 'content')
-
- def test_send_minimal_progress(self):
- # Even if we occasionally get 0 bytes sent, we still progress and
- # finish
- class SlowSendingSocket(object):
- def __init__(self):
- self.call_count = 0
- def send(self, bytes):
- self.call_count += 1
- if self.call_count > 100:
- # Prevent the test suite from hanging
- raise RuntimeError('too many calls')
- if self.call_count % 3 == 0:
- return 0
- return 1
- sock = SlowSendingSocket()
- osutils.send_all(sock, 'a reasonable amount of content')
- self.assertEqual(44, sock.call_count)
+ self.assertRaises(errors.ConnectionReset,
+ osutils.send_all, sock, 'content')
+ self.assertEqual(1, sock.call_count)
class TestPosixFuncs(tests.TestCase):
More information about the bazaar-commits
mailing list