Skip to content

Commit

Permalink
[App] Extend retry to 4xx except 400, 401, 403, 404 (#19842)
Browse files Browse the repository at this point in the history
* Extend retry to 4xx except 400, 401, 403, 404

* Remove unused intersphinx mapping for app

---------

Co-authored-by: awaelchli <[email protected]>
  • Loading branch information
lantiga and awaelchli authored May 19, 2024
1 parent c8059d7 commit d5bf4b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/lightning/app/utilities/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/tests_app/utilities/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]

Expand All @@ -61,14 +62,16 @@ 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),
]


@mock.patch("urllib3.connectionpool.HTTPConnectionPool._get_conn")
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()),
]

Expand All @@ -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),
]

0 comments on commit d5bf4b9

Please sign in to comment.