Skip to content

fix(retry): retry on aiohttp and google-auth timeout exceptions with HttpRetryOptions - #3330

Open
rladeira wants to merge 1 commit into
googleapis:mainfrom
rladeira:fix/aiohttp-timeout-retry
Open

rladeira wants to merge 1 commit into
googleapis:mainfrom
rladeira:fix/aiohttp-timeout-retry

Conversation

@rladeira

Copy link
Copy Markdown

Closes #3329.

Summary

When HttpRetryOptions is configured and aiohttp is active (google-genai[aiohttp]), transient request timeouts and google.auth.aio-wrapped transport errors bypassed retry_args() and surfaced on the first attempt.

  • Add asyncio.TimeoutError (which also covers aiohttp.ServerTimeoutError and aiohttp.ConnectionTimeoutError) and google.auth.exceptions.TimeoutError (raised by google.auth.aio.transport.aiohttp.Request and AsyncAuthorizedSession.request on timeout) to _AIOHTTP_TRANSIENT_EXC, matching httpx.TimeoutException in _HTTPX_TRANSIENT_EXC (httpx.TimeoutException is not retried despite HttpRetryOptions being configured #2337 / fix(retry): retry on httpx.TimeoutException with HttpRetryOptions #2345).
  • In retry_args(), also match google.auth.exceptions.TransportError when e.__cause__ is an instance of _AIOHTTP_TRANSIENT_EXC, aligning retry_args() with _async_request_once()'s except (..., auth_exceptions.TransportError): raise # HttpRetryOptions owns retries; tenacity decides while keeping non-transient errors (aiohttp.ClientPayloadError, google.auth.exceptions.RefreshError) non-retriable.
  • Keep the default behavior when HttpRetryOptions is unset unchanged (client-side timeouts are not implicitly retried without retry_options).
  • Add unit tests in google/genai/tests/client/test_aiohttp_retries.py covering retry_args() predicates and async_request() retry behavior for asyncio.TimeoutError and google.auth.exceptions.TimeoutError.

Testing

$ pytest google/genai/tests/client/test_aiohttp_retries.py google/genai/tests/client/test_retries.py -q
53 passed in 30.13s

$ mypy google/genai/_api_client.py
Success: no issues found in 1 source file

$ git diff --check

…HttpRetryOptions

Include asyncio.TimeoutError and google.auth.exceptions.TimeoutError in
_AIOHTTP_TRANSIENT_EXC, and match google.auth.exceptions.TransportError
when its __cause__ is in _AIOHTTP_TRANSIENT_EXC, so async requests using
aiohttp or AsyncAuthorizedSession retry transient timeouts and connection
drops when HttpRetryOptions is configured (matching httpx in googleapis#2345).

Fixes googleapis#3329.

This branch has not been deployed

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

Labels

size:XL Code changes > 100 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aiohttp timeout and wrapped google-auth transport exceptions are not retried despite HttpRetryOptions being configured

2 participants