Skip to content

Retry on HTTP 200 with empty response body#603

Open
emanuelsdsj wants to merge 1 commit intotrinodb:masterfrom
emanuelsdsj:fix/retry-on-empty-200-response
Open

Retry on HTTP 200 with empty response body#603
emanuelsdsj wants to merge 1 commit intotrinodb:masterfrom
emanuelsdsj:fix/retry-on-empty-200-response

Conversation

@emanuelsdsj
Copy link
Copy Markdown
Member

@emanuelsdsj emanuelsdsj commented Apr 30, 2026

Description

fixed #596

TrinoRequest.process() calls json.loads(http_response.text)
immediately after checking http_response.ok. When Trino returns
HTTP 200 with an empty body under load, this raises a bare
JSONDecodeError that is not in the handled_exceptions list of
_retry_with, so no retry is attempted and the exception
propagates unhandled to the caller.

Two changes to address this:

  • Add a retry condition in max_attempts.setter for HTTP 200
    responses with an empty body, so the existing exponential
    backoff mechanism retries them — consistent with how 429/502/
    503/504 are already handled.
  • Add a guard in process() that raises TrinoConnectionError
    with a descriptive message if an empty body reaches that point
    (e.g. after retries are exhausted), instead of leaking a raw
    JSONDecodeError.

Non-technical explanation

When the server returned an empty response under load, the client
crashed with an unhelpful JSONDecodeError. It now retries
automatically and, if retries are exhausted, raises a clear error
message.

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text:

* Fix client crash with `JSONDecodeError` on HTTP 200 with empty
  response body by retrying the request. ({issue}`596`)

When Trino returns HTTP 200 with an empty body under load, the
client was crashing with a bare JSONDecodeError. Treat this as
a transient condition and retry using the existing backoff
mechanism, consistent with how 429/502/503/504 are handled.
If retries are exhausted, raise TrinoConnectionError with a
descriptive message.

Fixes trinodb#596
@cla-bot cla-bot Bot added the cla-signed label Apr 30, 2026
@emanuelsdsj emanuelsdsj requested a review from hashhar April 30, 2026 17:47
@emanuelsdsj
Copy link
Copy Markdown
Member Author

I believe that both failures are related to the installation of dependencies, even before any tests were run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

TrinoRequest.process() crashes with JSONDecodeError on empty 200 response instead of retrying

1 participant