Skip to content

Commit

Permalink
Fixes #960 - Do a retry if exc has errno but errno is None. Python3 s…
Browse files Browse the repository at this point in the history
…upport.

Since py 3, there are new "OS-exception" including RemoteDisconnected.

Sadly, these exception are oserror and are supposed to have an errno
field, but if they are raised by some parts of cpython will not have any
value for errno.

That is the case for RemoteDisconnected raised by httlib instead of
BadStatusLine previously.
  • Loading branch information
fviard committed Jun 3, 2018
1 parent 290b811 commit b4f1424
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,15 @@ def send_request(self, request, retries = _max_retries):
ConnMan.put(conn)
except (IOError, Exception) as e:
debug("Response:\n" + pprint.pformat(response))
if ((hasattr(e, 'errno') and e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e) or "[Errno 32]" in str(e)) and not isinstance(e, SocketTimeoutException):
if ((hasattr(e, 'errno') and e.errno
and e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e)
or "[Errno 32]" in str(e)
) and not isinstance(e, SocketTimeoutException):
raise
# When the connection is broken, BadStatusLine is raised with py2
# and RemoteDisconnected is raised by py3 with a trap:
# RemoteDisconnected has an errno field with a None value.
if conn:
# close the connection and re-establish
conn.counter = ConnMan.conn_max_counter
Expand Down Expand Up @@ -1474,8 +1480,10 @@ def send_file(self, request, stream, labels, buffer = '', throttle = 0,
progress.done("failed")
if retries:
known_error = False
if ((hasattr(e, 'errno') and e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e) or "[Errno 32]" in str(e)) and not isinstance(e, SocketTimeoutException):
if ((hasattr(e, 'errno') and e.errno
and e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e) or "[Errno 32]" in str(e)
) and not isinstance(e, SocketTimeoutException):
# We have to detect these errors by looking at the error string
# Connection reset by peer and Broken pipe
# The server broke the connection early with an error like
Expand Down Expand Up @@ -1659,8 +1667,10 @@ def recv_file(self, request, stream, labels, start_position = 0, retries = _max_
except (IOError, Exception) as e:
if self.config.progress_meter:
progress.done("failed")
if ((hasattr(e, 'errno') and e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e) or "[Errno 32]" in str(e)) and not isinstance(e, SocketTimeoutException):
if ((hasattr(e, 'errno') and e.errno and
e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e) or "[Errno 32]" in str(e)
) and not isinstance(e, SocketTimeoutException):
raise
if conn:
# close the connection and re-establish
Expand Down Expand Up @@ -1753,8 +1763,10 @@ def recv_file(self, request, stream, labels, start_position = 0, retries = _max_
except (IOError, Exception) as e:
if self.config.progress_meter:
progress.done("failed")
if ((hasattr(e, 'errno') and e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e) or "[Errno 32]" in str(e)) and not isinstance(e, SocketTimeoutException):
if ((hasattr(e, 'errno') and e.errno
and e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT))
or "[Errno 104]" in str(e) or "[Errno 32]" in str(e)
) and not isinstance(e, SocketTimeoutException):
raise
# close the connection and re-establish
conn.counter = ConnMan.conn_max_counter
Expand Down

0 comments on commit b4f1424

Please sign in to comment.