Repository navigation
Stop retrying HTTP 504, the server's statement timeout - #39
Merged
Merged
Conversation
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
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>
pedroripper
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #33.
The problem
The session retried
[502, 503, 504]three times. On this API a 504 is not transient:lakehouse_serveranswers it from_runinapp/querying/router.pywhen the connection's 60 sstatement_timeout(QUERY_STATEMENT_TIMEOUT_SECONDS) cancels the query, with adetailsaying how to narrow it. That path serves bothPOST /query/andGET /query/last-updated/{table}. So a retry:RetryError("too many 504 error responses"), which skips_http_errorand becomesLakehouseError("Request to <url> failed: ..."), with no status and nodetail.502 and 503 lost their
detailthe same way once their retries ran out.The change
connector.py: 504 leavesstatus_forcelist. A 504 now reachesraise_for_status()on the first answer and goes through_http_errortoLakehouseError("HTTP 504 Gateway Timeout for <url>: <detail>"), in bothpostandget.connector.py:raise_on_status=Falseon theRetry. 502 and 503 are still retried three times; when the retries run out, the last response comes back and is raised asHTTP 503 ... for <url>: <detail>instead ofRetryError.connector.py: the health check callsraise_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 passedinitialize(). The server's/health-check/always answers 200, so nothing else changes there.connector.py:gettimes out at 90 s instead of 60 s. At 60 s, the same as the server's statement timeout, alast_updatedchunk 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 aReadTimeoutwithout the detail.docs/api.rst: one line underLakehouseErrorsaying a 504 is not retried and carries the advice.Tests
test_a_504_is_raised_once_with_the_server_detail(POST and GET): one request, and the error carriesHTTP 504and the server's detail. Fails onmasterwith theRetryErrormessage.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, thenHTTP 502/HTTP 503with the detail. Fails withoutraise_on_status=False.test_initialize_health_check_failure_error_status: a 503 with a JSON body failsinitialize(). Fails withraise_on_status=Falsealone.test_initialize_creates_session_with_retriesnow expects{502, 503}andraise_on_status is False.uv run pytest tests/unit/: 80 passed.RetryError, no detailHTTP 504 ...: <detail>RetryError, no detailHTTP 504 ...: <detail>RetryError, no detailHTTP 503 ...: <detail>Health check failedHealth check failedThe
gettimeout, with the times scaled down (server answers 504 after 1.5 s): a 1 s read timeout gives 4 requests and aReadTimeoutwith no detail; a 3 s one gives 1 request andHTTP 504with 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 ...toHTTP <status> <reason> for <url>: <detail>. A health check answered with any error status now failsinitialize(); before, one outside the retried statuses passed if its body was truthy JSON.Left out
Read timeouts are still retried. With
getat 90 s andpostat 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 passespostatimeoutof 60 s or less is still retried four times.