diff --git a/src/lightning/app/utilities/network.py b/src/lightning/app/utilities/network.py index 04afdb0b4f92c..a7cc00fde52b7 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 38c8961919db6..3a14c0301ef1e 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), ]