Skip to content

Commit d113ed4

Browse files
MukundaKattacopybara-github
authored andcommitted
Copybara import of the project:
-- b5c7090 by Mukunda Rao Katta <[email protected]>: fix(retry): retry on httpx.TimeoutException with HttpRetryOptions The retry predicate in `retry_args` only matched `errors.APIError` subclasses, so lower-level httpx transport exceptions (`httpx.TimeoutException`, `httpx.ConnectError`, and their subclasses such as `ReadTimeout` / `ConnectTimeout`) were silently dropped and never retried, even when `HttpRetryOptions` was explicitly configured. Long-running LLM inference calls regularly hit transient transport errors from load balancers, NAT gateways, and idle TCP timeouts. Vertex AI's retry strategy guidance lists socket timeouts and TCP disconnects as retryable, so honoring those here matches user expectations. Fixes #2337. FUTURE_COPYBARA_INTEGRATE_REVIEW=#2345 from MukundaKatta:fix/retry-httpx-timeout 9b2d886 PiperOrigin-RevId: 906620787
1 parent f8a2e7e commit d113ed4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎google/genai/tests/client/test_retries.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ def test_retry_args_enabled_with_custom_values_are_not_overridden():
187187
assert not retry.predicate(e)
188188

189189

190+
def test_retry_args_retries_httpx_transport_errors():
191+
# httpx transport errors (timeouts, connect errors) bypass APIError but are
192+
# transient infrastructure failures, so the predicate must still retry them
193+
# when HttpRetryOptions is configured. See issue #2337.
194+
args = api_client.retry_args(types.HttpRetryOptions())
195+
retry = args['retry']
196+
197+
assert retry.predicate(httpx.TimeoutException('stalled'))
198+
assert retry.predicate(httpx.ReadTimeout('read stalled'))
199+
assert retry.predicate(httpx.ConnectTimeout('connect stalled'))
200+
assert retry.predicate(httpx.ConnectError('connect refused'))
201+
202+
# Unrelated transport errors are not retried.
203+
assert not retry.predicate(httpx.InvalidURL('bad url'))
204+
assert not retry.predicate(ValueError('not a transport error'))
205+
206+
190207
def _patch_auth_default():
191208
return mock.patch(
192209
'google.auth.default',

0 commit comments

Comments
 (0)