From 88ab76b357893cb83c55c92df6b31a728ea5e796 Mon Sep 17 00:00:00 2001 From: Thomas Bonfort Date: Tue, 19 Apr 2016 08:48:53 +0200 Subject: [PATCH] Retry requests on broken pipe and aborted connection (#218) --- googleapiclient/http.py | 2 +- tests/test_http.py | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/googleapiclient/http.py b/googleapiclient/http.py index ed074cb5c0f..6395f9677c7 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 b74e2cbf113..08450473a69 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -122,14 +122,19 @@ def request(self, *args, **kwargs): 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 @@ def request(self, *args, **kwargs): 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