Skip to content

Commit

Permalink
fix: Retry Connection broken and Connection reset requests errors (
Browse files Browse the repository at this point in the history
…#794)

Closes: SDK-2904
  • Loading branch information
lukaszsocha2 committed Jan 27, 2023
1 parent c0b2cd4 commit f1a0aa4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion boxsdk/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ def _prepare_and_send_request(
network_response = None
if 'EOF occurred in violation of protocol' in str(request_exc):
reauthentication_needed = True
elif 'Connection aborted' in str(request_exc):
elif any(text in str(request_exc) for text in [
'Connection aborted', 'Connection broken', 'Connection reset'
]):
reauthentication_needed = False
else:
raise
Expand Down
10 changes: 8 additions & 2 deletions test/unit/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,14 @@ def test_box_session_raises_for_failed_response(box_session, mock_network_layer,
box_session.get(url=test_url)


def test_box_session_retries_connection_aborted_exception(box_session, mock_network_layer, generic_successful_request_response, test_url):
mock_network_layer.request.side_effect = [RequestsConnectionError('Connection aborted'), generic_successful_request_response]
@pytest.mark.parametrize('exc_message', [
'Connection aborted',
"Connection broken: ConnectionResetError(54, 'Connection reset by peer')"
])
def test_box_session_retries_connection_aborted_exception(
box_session, mock_network_layer, generic_successful_request_response, test_url, exc_message
):
mock_network_layer.request.side_effect = [RequestsConnectionError(exc_message), generic_successful_request_response]
mock_network_layer.retry_after.side_effect = lambda delay, request, *args, **kwargs: request(*args, **kwargs)

box_response = box_session.get(url=test_url)
Expand Down

0 comments on commit f1a0aa4

Please sign in to comment.