Rev 4630: More complete fix. in file:///home/vila/src/bzr/bugs/306264-pycurl-recv-error/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Aug 19 17:33:39 BST 2009
At file:///home/vila/src/bzr/bugs/306264-pycurl-recv-error/
------------------------------------------------------------
revno: 4630
revision-id: v.ladeuil+lp at free.fr-20090819163339-80g9c3lad00wpe0v
parent: v.ladeuil+lp at free.fr-20090819093407-t3bk5g5dn8cn8qjc
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 306264-pycurl-recv-error
timestamp: Wed 2009-08-19 18:33:39 +0200
message:
More complete fix.
* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractHTTPHandler.retry_or_raise): ECONNRESET should be
translated into ConnectionReset. It's pretty rare that it can
occur during the request sending, but it has been observed during
selftest runs.
* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._curl_perform): Turns CURLE_RECV_ERROR into a
ConnectionReset instead of a ConnectionError or some callers won't
catch it properly.
* bzrlib/transport/http/__init__.py:
(SmartClientHTTPMedium.send_http_smart_request): Catch
ConnectionReset and turn into a SmartProtocolError like for
InvalidHttpResponse.
* bzrlib/tests/test_http.py:
(TestWallServer.test_http_has, TestWallServer.test_http_get):
ConnectionReset can be raised too.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2009-06-10 03:56:49 +0000
+++ b/bzrlib/tests/test_http.py 2009-08-19 16:33:39 +0000
@@ -625,14 +625,17 @@
# for details) make no distinction between a closed
# socket and badly formatted status line, so we can't
# just test for ConnectionError, we have to test
- # InvalidHttpResponse too.
- self.assertRaises((errors.ConnectionError, errors.InvalidHttpResponse),
+ # InvalidHttpResponse too. And pycurl may raise ConnectionReset
+ # instead of ConnectionError too.
+ self.assertRaises(( errors.ConnectionError, errors.ConnectionReset,
+ errors.InvalidHttpResponse),
t.has, 'foo/bar')
def test_http_get(self):
server = self.get_readonly_server()
t = self._transport(server.get_url())
- self.assertRaises((errors.ConnectionError, errors.InvalidHttpResponse),
+ self.assertRaises((errors.ConnectionError, errors.ConnectionReset,
+ errors.InvalidHttpResponse),
t.get, 'foo/bar')
=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py 2009-04-27 03:27:46 +0000
+++ b/bzrlib/transport/http/__init__.py 2009-08-19 16:33:39 +0000
@@ -617,7 +617,7 @@
raise InvalidHttpResponse(
t._remote_path('.bzr/smart'),
'Expected 200 response code, got %r' % (code,))
- except errors.InvalidHttpResponse, e:
+ except (errors.InvalidHttpResponse, errors.ConnectionReset), e:
raise errors.SmartProtocolError(str(e))
return body_filelike
=== modified file 'bzrlib/transport/http/_pycurl.py'
--- a/bzrlib/transport/http/_pycurl.py 2009-08-19 09:34:07 +0000
+++ b/bzrlib/transport/http/_pycurl.py 2009-08-19 16:33:39 +0000
@@ -363,12 +363,14 @@
CURLE_COULDNT_RESOLVE_PROXY,
CURLE_COULDNT_CONNECT,
CURLE_GOT_NOTHING,
- CURLE_RECV_ERROR,
CURLE_SSL_CACERT,
CURLE_SSL_CACERT_BADFILE,
):
raise errors.ConnectionError(
'curl connection error (%s)\non %s' % (e[1], url))
+ elif e[0] == CURLE_RECV_ERROR:
+ raise errors.ConnectionReset(
+ 'curl connection error (%s)\non %s' % (e[1], url))
elif e[0] == CURLE_PARTIAL_FILE:
# Pycurl itself has detected a short read. We do not have all
# the information for the ShortReadvError, but that should be
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2009-05-04 15:21:26 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2009-08-19 16:33:39 +0000
@@ -46,6 +46,7 @@
# actual code more or less do that, tests should be written to
# ensure that.
+import errno
import httplib
try:
import kerberos
@@ -541,6 +542,10 @@
request.get_full_url(),
'Bad status line received',
orig_error=exc_val)
+ elif (isinstance(exc_val, socket.error) and len(exc_val.args)
+ and exc_val.args[0] in (errno.ECONNRESET, 10054)):
+ raise errors.ConnectionReset(
+ "Connection lost while sending request.")
else:
# All other exception are considered connection related.
More information about the bazaar-commits
mailing list