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

fix: Retry Connection broken and Connection reset requests errors #794

Merged
merged 1 commit into from
Jan 27, 2023
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
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 @@ -222,8 +222,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