Skip to content

Commit 713b1de

Browse files
Merge pull request googleapis#219 from tbonfort/patch-1
Retry requests on broken pipe and aborted connection.
2 parents 6d9ba51 + 88ab76b commit 713b1de

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

googleapiclient/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
158158
except socket.error as socket_error:
159159
# errno's contents differ by platform, so we have to match by name.
160160
if socket.errno.errorcode.get(socket_error.errno) not in (
161-
'WSAETIMEDOUT', 'ETIMEDOUT', ):
161+
'WSAETIMEDOUT', 'ETIMEDOUT', 'EPIPE', 'ECONNABORTED', ):
162162
raise
163163
exception = socket_error
164164

tests/test_http.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,19 @@ def request(self, *args, **kwargs):
122122
ex = TimeoutError()
123123
else:
124124
ex = socket.error()
125-
# Initialize the timeout error code to the platform's error code.
126-
try:
127-
# For Windows:
128-
ex.errno = socket.errno.WSAETIMEDOUT
129-
except AttributeError:
130-
# For Linux/Mac:
131-
ex.errno = socket.errno.ETIMEDOUT
132-
# Now raise the correct timeout error.
125+
126+
if self.num_errors == 2:
127+
#first try a broken pipe error (#218)
128+
ex.errno = socket.errno.EPIPE
129+
else:
130+
# Initialize the timeout error code to the platform's error code.
131+
try:
132+
# For Windows:
133+
ex.errno = socket.errno.WSAETIMEDOUT
134+
except AttributeError:
135+
# For Linux/Mac:
136+
ex.errno = socket.errno.ETIMEDOUT
137+
# Now raise the correct error.
133138
raise ex
134139

135140

@@ -145,7 +150,7 @@ def request(self, *args, **kwargs):
145150
else:
146151
self.num_errors -= 1
147152
ex = socket.error()
148-
# Initialize the timeout error code to the platform's error code.
153+
# set errno to a non-retriable value
149154
try:
150155
# For Windows:
151156
ex.errno = socket.errno.WSAECONNREFUSED

0 commit comments

Comments
 (0)