From 892be1f0f90216628b937b721a6838f4a194f165 Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Thu, 17 Jul 2014 17:05:00 -0700 Subject: [PATCH] Retry connection timeouts Now that we've set a connection timeout, we need to retry these just like a generic ConectionError from requests. --- botocore/retryhandler.py | 4 ++-- tests/unit/test_retryhandler.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/botocore/retryhandler.py b/botocore/retryhandler.py index cd265be640..857916e321 100644 --- a/botocore/retryhandler.py +++ b/botocore/retryhandler.py @@ -17,7 +17,7 @@ import logging from binascii import crc32 -from botocore.vendored.requests import ConnectionError +from botocore.vendored.requests import ConnectionError, Timeout from botocore.vendored.requests.packages.urllib3.exceptions import ClosedPoolError from botocore.exceptions import ChecksumError @@ -29,7 +29,7 @@ # to get more specific exceptions from requests we can update # this mapping with more specific exceptions. EXCEPTION_MAP = { - 'GENERAL_CONNECTION_ERROR': [ConnectionError, ClosedPoolError], + 'GENERAL_CONNECTION_ERROR': [ConnectionError, ClosedPoolError, Timeout], } diff --git a/tests/unit/test_retryhandler.py b/tests/unit/test_retryhandler.py index 97752d4be8..d4f099238d 100644 --- a/tests/unit/test_retryhandler.py +++ b/tests/unit/test_retryhandler.py @@ -16,7 +16,7 @@ from tests import unittest import mock -from botocore.vendored.requests import ConnectionError +from botocore.vendored.requests import ConnectionError, Timeout from botocore.vendored.requests.packages.urllib3.exceptions import ClosedPoolError from botocore import retryhandler @@ -213,6 +213,15 @@ def test_create_retry_handler_with_socket_errors(self): sleep_time = handler(response=None, attempts=1, caught_exception=ValueError()) + def test_connection_timeouts_are_retried(self): + # If a connection times out, we get a Timout exception + # from requests. We should be retrying those. + handler = retryhandler.create_retry_handler( + self.retry_config, operation_name='OperationBar') + sleep_time = handler(response=None, attempts=1, + caught_exception=Timeout()) + self.assertEqual(sleep_time, 1) + def test_retry_pool_closed_errors(self): # A ClosedPoolError is retried (this is a workaround for a urllib3 # bug). Can be removed once we upgrade to requests 2.0.0.