Skip to content

Commit 6509913

Browse files
d-coleebyhr
authored andcommitted
Retry on 502 bad gateway responses
1 parent 7a98fbe commit 6509913

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

tests/unit/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ def test_authentication_fail_retry(monkeypatch):
753753

754754

755755
@pytest.mark.parametrize("status_code, attempts", [
756+
(502, 3),
756757
(503, 3),
757758
(504, 3),
758759
])

trino/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ def max_attempts(self, value) -> None:
340340
self._handle_retry,
341341
exceptions=self._exceptions,
342342
conditions=(
343-
# need retry when there is no exception but the status code is 503 or 504
343+
# need retry when there is no exception but the status code is 502, 503, or 504
344344
lambda response: getattr(response, "status_code", None)
345-
in (503, 504),
345+
in (502, 503, 504),
346346
),
347347
max_attempts=self._max_attempts,
348348
)
@@ -416,6 +416,9 @@ def _process_error(self, error, query_id):
416416
return exceptions.TrinoQueryError(error, query_id)
417417

418418
def raise_response_error(self, http_response):
419+
if http_response.status_code == 502:
420+
raise exceptions.Http502Error("error 502: bad gateway")
421+
419422
if http_response.status_code == 503:
420423
raise exceptions.Http503Error("error 503: service unavailable")
421424

trino/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class HttpError(Exception):
2929
pass
3030

3131

32+
class Http502Error(Exception):
33+
pass
34+
35+
3236
class Http503Error(HttpError):
3337
pass
3438

0 commit comments

Comments
 (0)