aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bonfort <thomas.bonfort@gmail.com>2016-04-19 08:48:53 +0200
committerThomas Bonfort <thomas.bonfort@gmail.com>2016-04-21 12:42:14 +0200
commit88ab76b357893cb83c55c92df6b31a728ea5e796 (patch)
treed2c47c71f3965b8ed098ec7bd36ed96e40a97689
parent133b9ff999d46d50756358e7b8e9f0bc039c67dd (diff)
downloadgoogle-api-python-client-88ab76b357893cb83c55c92df6b31a728ea5e796.tar.gz
Retry requests on broken pipe and aborted connection (#218)
-rw-r--r--googleapiclient/http.py2
-rw-r--r--tests/test_http.py23
2 files changed, 15 insertions, 10 deletions
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index ed074cb5c..6395f9677 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -151,7 +151,7 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
except socket.error as socket_error:
# errno's contents differ by platform, so we have to match by name.
if socket.errno.errorcode.get(socket_error.errno) not in (
- 'WSAETIMEDOUT', 'ETIMEDOUT', ):
+ 'WSAETIMEDOUT', 'ETIMEDOUT', 'EPIPE', 'ECONNABORTED', ):
raise
exception = socket_error
diff --git a/tests/test_http.py b/tests/test_http.py
index b74e2cbf1..08450473a 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -122,14 +122,19 @@ class HttpMockWithErrors(object):
ex = TimeoutError()
else:
ex = socket.error()
- # Initialize the timeout error code to the platform's error code.
- try:
- # For Windows:
- ex.errno = socket.errno.WSAETIMEDOUT
- except AttributeError:
- # For Linux/Mac:
- ex.errno = socket.errno.ETIMEDOUT
- # Now raise the correct timeout error.
+
+ if self.num_errors == 2:
+ #first try a broken pipe error (#218)
+ ex.errno = socket.errno.EPIPE
+ else:
+ # Initialize the timeout error code to the platform's error code.
+ try:
+ # For Windows:
+ ex.errno = socket.errno.WSAETIMEDOUT
+ except AttributeError:
+ # For Linux/Mac:
+ ex.errno = socket.errno.ETIMEDOUT
+ # Now raise the correct error.
raise ex
@@ -145,7 +150,7 @@ class HttpMockWithNonRetriableErrors(object):
else:
self.num_errors -= 1
ex = socket.error()
- # Initialize the timeout error code to the platform's error code.
+ # set errno to a non-retriable value
try:
# For Windows:
ex.errno = socket.errno.WSAECONNREFUSED