From d5bf4b9ed3866633c32cf53a5c9920adab78cdc7 Mon Sep 17 00:00:00 2001 From: Luca Antiga Date: Sat, 18 May 2024 22:03:16 -0400 Subject: [PATCH] [App] Extend retry to 4xx except 400, 401, 403, 404 (#19842) * Extend retry to 4xx except 400, 401, 403, 404 * Remove unused intersphinx mapping for app --------- Co-authored-by: awaelchli --- src/lightning/app/utilities/network.py | 10 +++++++--- tests/tests_app/utilities/test_network.py | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lightning/app/utilities/network.py b/src/lightning/app/utilities/network.py index 04afdb0b4f..a7cc00fde5 100644 --- a/src/lightning/app/utilities/network.py +++ b/src/lightning/app/utilities/network.py @@ -96,10 +96,14 @@ def create_retry_strategy(): # are going to be alive for a very long time (~ 4 days) but retries every 120 seconds total=_CONNECTION_RETRY_TOTAL, backoff_factor=_CONNECTION_RETRY_BACKOFF_FACTOR, + # Any 4xx and 5xx statuses except + # 400 Bad Request + # 401 Unauthorized + # 403 Forbidden + # 404 Not Found status_forcelist={ - 408, # Request Timeout - 429, # Too Many Requests - *range(500, 600), # Any 5xx Server Error status + 402, + *range(405, 600), }, allowed_methods={ "POST", # Default methods are idempotent, add POST here diff --git a/tests/tests_app/utilities/test_network.py b/tests/tests_app/utilities/test_network.py index 38c8961919..3a14c0301e 100644 --- a/tests/tests_app/utilities/test_network.py +++ b/tests/tests_app/utilities/test_network.py @@ -49,7 +49,8 @@ def test_find_free_network_port_cloudspace(_, patch_constants): def test_http_client_retry_post(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ mock.Mock(status=500, msg=HTTPMessage()), - mock.Mock(status=429, msg=HTTPMessage()), + mock.Mock(status=599, msg=HTTPMessage()), + mock.Mock(status=405, msg=HTTPMessage()), mock.Mock(status=200, msg=HTTPMessage()), ] @@ -61,6 +62,7 @@ def test_http_client_retry_post(getconn_mock): mock.call("POST", "/test", body=None, headers=mock.ANY), mock.call("POST", "/test", body=None, headers=mock.ANY), mock.call("POST", "/test", body=None, headers=mock.ANY), + mock.call("POST", "/test", body=None, headers=mock.ANY), ] @@ -68,7 +70,8 @@ def test_http_client_retry_post(getconn_mock): def test_http_client_retry_get(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ mock.Mock(status=500, msg=HTTPMessage()), - mock.Mock(status=429, msg=HTTPMessage()), + mock.Mock(status=599, msg=HTTPMessage()), + mock.Mock(status=405, msg=HTTPMessage()), mock.Mock(status=200, msg=HTTPMessage()), ] @@ -80,4 +83,5 @@ def test_http_client_retry_get(getconn_mock): mock.call("GET", "/test", body=None, headers=mock.ANY), mock.call("GET", "/test", body=None, headers=mock.ANY), mock.call("GET", "/test", body=None, headers=mock.ANY), + mock.call("GET", "/test", body=None, headers=mock.ANY), ]