Skip to content

Commit

Permalink
Merge pull request #1191 from kyleknap/s3-readtimeout
Browse files Browse the repository at this point in the history
Add retry logic for read timeouts for s3 commands
  • Loading branch information
kyleknap committed Mar 2, 2015
2 parents a026913 + 06966be commit 4b1156f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CHANGELOG
Next Release (TBD)
==================

* bugfix:``aws s3``: Fix issue where read timeouts were not retried.
(`issue 1191 <https://github.com/aws/aws-cli/pull/1191>`__)
* feature:``aws cloudtrail``: Add support for regionalized policy templates
for the ``create-subscription`` and ``update-subscription`` commands.
(`issue 1167 <https://github.com/aws/aws-cli/pull/1167>`__)
Expand Down
6 changes: 4 additions & 2 deletions awscli/customizations/s3/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from botocore.vendored import requests
from botocore.exceptions import IncompleteReadError
from botocore.vendored.requests.packages.urllib3.exceptions import \
ReadTimeoutError

from awscli.customizations.s3.utils import find_bucket_key, MD5Error, \
operate, ReadFileChunk, relative_path, IORequest, IOCloseRequest, \
Expand Down Expand Up @@ -383,8 +385,8 @@ def _download_part(self):
self._result_queue.put(PrintTask(**result))
LOGGER.debug("Task complete: %s", self)
return
except (socket.timeout, socket.error) as e:
LOGGER.debug("Socket timeout caught, retrying request, "
except (socket.timeout, socket.error, ReadTimeoutError) as e:
LOGGER.debug("Timeout error caught, retrying request, "
"(attempt %s / %s)", i, self.TOTAL_ATTEMPTS,
exc_info=True)
continue
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/customizations/s3/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import socket

from botocore.exceptions import IncompleteReadError
from botocore.vendored.requests.packages.urllib3.exceptions import \
ReadTimeoutError

from awscli.customizations.s3 import transferconfig
from awscli.customizations.s3.tasks import CreateLocalFileTask
Expand Down Expand Up @@ -396,6 +398,18 @@ def test_incomplete_read_is_retried(self):
self.assertEqual(DownloadPartTask.TOTAL_ATTEMPTS,
self.service.get_operation.call_count)

def test_readtimeout_is_retried(self):
self.service.get_operation.return_value.call.side_effect = \
ReadTimeoutError(None, None, None)
task = DownloadPartTask(0, 1024 * 1024, self.result_queue,
self.service, self.filename,
self.context, self.io_queue)
with self.assertRaises(RetriesExeededError):
task()
self.context.cancel.assert_called_with()
self.assertEqual(DownloadPartTask.TOTAL_ATTEMPTS,
self.service.get_operation.call_count)

def test_retried_requests_dont_enqueue_writes_twice(self):
error_body = mock.Mock()
error_body.read.side_effect = socket.timeout
Expand Down

0 comments on commit 4b1156f

Please sign in to comment.