Skip to content

Commit

Permalink
[Core] Handle requests connection timeout error (#7542)
Browse files Browse the repository at this point in the history
* Handle requests connection timeout error

* Moved catch

* Added test

* Update test to be more stable
  • Loading branch information
annatisch authored Oct 3, 2019
1 parent 1fadf24 commit e872266
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def send(self, request, **kwargs): # type: ignore
allow_redirects=False,
**kwargs)

except urllib3.exceptions.NewConnectionError as err:
except (urllib3.exceptions.NewConnectionError, urllib3.exceptions.ConnectTimeoutError) as err:
error = ServiceRequestError(err, error=err)
except requests.exceptions.ReadTimeout as err:
error = ServiceResponseError(err, error=err)
Expand Down
16 changes: 15 additions & 1 deletion sdk/core/azure-core/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
RequestsTransport
)

from azure.core.configuration import Configuration
from azure.core.exceptions import AzureError


def test_sans_io_exception():
Expand Down Expand Up @@ -107,6 +107,20 @@ def test_basic_requests(self):
assert pipeline._transport.session is None
assert response.http_response.status_code == 200

def test_requests_socket_timeout(self):
conf = Configuration()
request = HttpRequest("GET", "https://bing.com")
policies = [
UserAgentPolicy("myusergant"),
RedirectPolicy()
]
# Sometimes this will raise a read timeout, sometimes a socket timeout depending on timing.
# Either way, the error should always be wrapped as an AzureError to ensure it's caught
# by the retry policy.
with pytest.raises(AzureError):
with Pipeline(RequestsTransport(), policies=policies) as pipeline:
response = pipeline.run(request, connection_timeout=0.000001)

def test_basic_requests_separate_session(self):

session = requests.Session()
Expand Down

0 comments on commit e872266

Please sign in to comment.