Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry logic for read timeouts for s3 commands #1191

Merged
merged 2 commits into from
Mar 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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