Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88ab76b

Browse files
committed
Retry requests on broken pipe and aborted connection (googleapis#218)
1 parent 133b9ff commit 88ab76b

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
@@ -151,7 +151,7 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
151151
except socket.error as socket_error:
152152
# errno's contents differ by platform, so we have to match by name.
153153
if socket.errno.errorcode.get(socket_error.errno) not in (
154-
'WSAETIMEDOUT', 'ETIMEDOUT', ):
154+
'WSAETIMEDOUT', 'ETIMEDOUT', 'EPIPE', 'ECONNABORTED', ):
155155
raise
156156
exception = socket_error
157157

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)