Skip to content

Stop retrying HTTP 504, the server's statement timeout - #39

Merged
guilherme-hu merged 4 commits into
masterfrom
gh/no-retry-504
Nov 17, 2026
Merged

guilherme-hu merged 4 commits into
masterfrom
gh/no-retry-504

Conversation

@guilherme-hu

@guilherme-hu guilherme-hu commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #33.

The problem

The session retried [502, 503, 504] three times. On this API a 504 is not transient: lakehouse_server answers it from _run in app/querying/router.py when the connection's 60 s statement_timeout (QUERY_STATEMENT_TIMEOUT_SECONDS) cancels the query, with a detail saying how to narrow it. That path serves both POST /query/ and GET /query/last-updated/{table}. So a retry:

  • ran the same query four times, about four minutes (4 × 60 s plus backoff);
  • ended in RetryError("too many 504 error responses"), which skips _http_error and becomes LakehouseError("Request to <url> failed: ..."), with no status and no detail.

502 and 503 lost their detail the same way once their retries ran out.

The change

  • connector.py: 504 leaves status_forcelist. A 504 now reaches raise_for_status() on the first answer and goes through _http_error to LakehouseError("HTTP 504 Gateway Timeout for <url>: <detail>"), in both post and get.
  • connector.py: raise_on_status=False on the Retry. 502 and 503 are still retried three times; when the retries run out, the last response comes back and is raised as HTTP 503 ... for <url>: <detail> instead of RetryError.
  • connector.py: the health check calls raise_for_status(). It only read the body, and an error body is truthy JSON, so with the flag above a persistent 502/503 would have passed initialize(). The server's /health-check/ always answers 200, so nothing else changes there.
  • connector.py: get times out at 90 s instead of 60 s. At 60 s, the same as the server's statement timeout, a last_updated chunk that ran out of time hit the client's read timeout before the 504 arrived; read timeouts are retried, so it was sent four times and ended in a ReadTimeout without the detail.
  • docs/api.rst: one line under LakehouseError saying a 504 is not retried and carries the advice.
  • Version 0.6.2 → 0.6.3 in its own commit, to drop if the release should be cut differently. No tag, release or publish was made.

Tests

  • test_a_504_is_raised_once_with_the_server_detail (POST and GET): one request, and the error carries HTTP 504 and the server's detail. Fails on master with the RetryError message.
  • test_a_502_or_503_is_still_retried: a 502 or 503 followed by a 200 returns the 200 after two requests.
  • test_a_502_or_503_that_persists_carries_the_server_detail: four requests, then HTTP 502/HTTP 503 with the detail. Fails without raise_on_status=False.
  • test_initialize_health_check_failure_error_status: a 503 with a JSON body fails initialize(). Fails with raise_on_status=False alone.
  • test_initialize_creates_session_with_retries now expects {502, 503} and raise_on_status is False.
  • uv run pytest tests/unit/: 80 passed.
  • Through the client's real session against a local HTTP server (no mocks), before and after:
before after
504 on POST 4 requests, RetryError, no detail 1 request, HTTP 504 ...: <detail>
504 on GET 4 requests, RetryError, no detail 1 request, HTTP 504 ...: <detail>
503, 503, 200 on GET 3 requests, 200 3 requests, 200
503 every time on POST 4 requests, RetryError, no detail 4 requests, HTTP 503 ...: <detail>
503 every time on the health check 4 requests, Health check failed 4 requests, Health check failed

The get timeout, with the times scaled down (server answers 504 after 1.5 s): a 1 s read timeout gives 4 requests and a ReadTimeout with no detail; a 3 s one gives 1 request and HTTP 504 with the detail.

Not re-run against the production API in this PR.

Compatibility

The message for a 504, and for a 502/503 that outlasts its retries, changes from Request to <url> failed: ... Max retries exceeded ... to HTTP <status> <reason> for <url>: <detail>. A health check answered with any error status now fails initialize(); before, one outside the retried statuses passed if its body was truthy JSON.

Left out

Read timeouts are still retried. With get at 90 s and post at 600 s by default, both above the server's 60 s statement timeout, a read timeout now means the API stopped answering rather than a query that ran out of time. A caller who passes post a timeout of 60 s or less is still retried four times.

lakehouse_server answers 504 when its 60 s statement_timeout cancels a
query, with a detail saying how to narrow it. Retrying ran the same query
four times (about four minutes) and ended in a RetryError that dropped
the status and the detail. A 504 now reaches raise_for_status() on the
first answer and is raised as LakehouseError with the server's detail.
502 and 503 are still retried.
With raise_on_status=False urllib3 hands back the last response instead
of raising "too many 503 error responses", so raise_for_status() reports
the status and the server's detail, as for any other HTTP error.

The health check now checks the status too. It only read the body, and
an error body is truthy JSON, so a 502/503 that outlasted the retries
would have passed initialize().
@guilherme-hu
guilherme-hu marked this pull request as ready for review November 16, 2026 23:50
get() timed out at 60 s, the same as the server's statement timeout, so
a last_updated() chunk that ran out of time hit the client's read
timeout before the 504 arrived. Read timeouts are retried: the query ran
four times and ended in a ReadTimeout without the server's detail. At
90 s the 504 arrives first and is raised once, with the detail.

The comment on 504 no longer says a retry swaps the server's advice for
"too many 504 error responses": raise_on_status=False keeps the detail.
What is left is the cost of running the same query again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@guilherme-hu
guilherme-hu merged commit 4813d14 into master Nov 17, 2026
2 checks passed
@guilherme-hu
guilherme-hu deleted the gh/no-retry-504 branch November 17, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't retry 504: it is the server's statement timeout, and retries hide its message

2 participants