Skip to content

Commit

Permalink
More changes for handling broken connections
Browse files Browse the repository at this point in the history
Handle ECONNRESET and EPIPE correctly

and simplify the code a bit (pull up conn.close()
while we're at it
  • Loading branch information
smurfix committed Nov 19, 2015
1 parent 6b055f4 commit 18ab47d
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions python3/httplib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,16 +996,18 @@ def _conn_request(self, conn, request_uri, method, body, headers):
errno_ = (e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno)
if errno_ in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
continue # retry on potentially transient errors
if errno_ in (errno.ECONNRESET, errno.EPIPE) and i == 1:
conn.close()
conn.connect()
continue # retry on closed connection
raise
except http.client.HTTPException:
if conn.sock is None:
conn.close()
if i < RETRIES-1:
conn.close()
conn.connect()
continue
else:
conn.close()
raise
raise
if i < RETRIES-1:
conn.close()
conn.connect()
Expand All @@ -1027,25 +1029,22 @@ def _conn_request(self, conn, request_uri, method, body, headers):
# If we get a BadStatusLine on the first try then that means
# the connection just went stale, so retry regardless of the
# number of RETRIES set.
conn.close()
if not seen_bad_status_line and i == 1:
i = 0
seen_bad_status_line = True
conn.close()
conn.connect()
continue
else:
conn.close()
raise
raise
except socket.timeout:
raise
except (socket.error, http.client.HTTPException):
except (socket.error, http.client.HTTPException) as e:
conn.close()
if i == 0:
conn.close()
errno_ = (e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno)
if errno_ in (errno.ECONNRESET, errno.EPIPE) and i == 1:
conn.connect()
continue
else:
raise
raise
break
return (response, content)

Expand Down

0 comments on commit 18ab47d

Please sign in to comment.