Skip to content

Commit

Permalink
Merge pull request #219 from tbonfort/patch-1
Browse files Browse the repository at this point in the history
Retry requests on broken pipe and aborted connection.
  • Loading branch information
nathanielmanistaatgoogle committed Apr 28, 2016
2 parents 6d9ba51 + 88ab76b commit 713b1de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion googleapiclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,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

Expand Down
23 changes: 14 additions & 9 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down

0 comments on commit 713b1de

Please sign in to comment.