Retry requests on broken pipe and aborted connection (#218)
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index ed074cb..6395f96 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -151,7 +151,7 @@
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 b74e2cb..0845047 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -122,14 +122,19 @@
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 @@
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