From 4ba151ca544d4dbc2ed75194b0780b7dfbbe3a4b Mon Sep 17 00:00:00 2001 From: kyleknap Date: Fri, 27 Feb 2015 16:47:11 -0800 Subject: [PATCH 1/2] Add retry logic for read timeouts for s3 commands --- awscli/customizations/s3/tasks.py | 6 ++++-- tests/unit/customizations/s3/test_tasks.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/awscli/customizations/s3/tasks.py b/awscli/customizations/s3/tasks.py index ab58078febaa..c9f07a3ca3c0 100644 --- a/awscli/customizations/s3/tasks.py +++ b/awscli/customizations/s3/tasks.py @@ -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, \ @@ -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 diff --git a/tests/unit/customizations/s3/test_tasks.py b/tests/unit/customizations/s3/test_tasks.py index cde6ad27511a..009a13601e88 100644 --- a/tests/unit/customizations/s3/test_tasks.py +++ b/tests/unit/customizations/s3/test_tasks.py @@ -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 @@ -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 From 06966be65960ffe58b6c79f0e6cac01d833d4141 Mon Sep 17 00:00:00 2001 From: kyleknap Date: Mon, 2 Mar 2015 13:46:14 -0800 Subject: [PATCH 2/2] Update Changelog with bug fix --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 39682429e5f2..1cb132dfebae 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,8 @@ CHANGELOG Next Release (TBD) ================== +* bugfix:``aws s3``: Fix issue where read timeouts were not retried. + (`issue 1191 `__) * feature:``aws cloudtrail``: Add support for regionalized policy templates for the ``create-subscription`` and ``update-subscription`` commands. (`issue 1167 `__)