fix(graphql): await retry backoff in AsyncGraphQL instead of blocking by superlevure · Pull Request #3472 · python-gitlab/python-gitlab
Repository navigation
fix(graphql): await retry backoff in AsyncGraphQL instead of blocking - #3472
Open
superlevure wants to merge 1 commit into python-gitlab:main from superlevure:fix/async-graphql-blocking-retry
Open
fix(graphql): await retry backoff in AsyncGraphQL instead of blocking #3472 superlevure wants to merge 1 commit into python-gitlab:main from superlevure:fix/async-graphql-blocking-retry
Conversation
superlevure commented Nov 19, 2026
Copy link Copy Markdown
Contributor
Changes
Closes #3471 .
AsyncGraphQL.execute handled retries through utils.Retry.handle_retry_on_status, which waits with a blocking time.sleep. In the async client that sleep runs on the event loop's thread, so the whole loop froze for the entire retry sequence: up to ~100 s of backoff with the default max_retries=10 and retry_transient_errors=True, or a full Retry-After on a 429 (with the default obey_rate_limit=True).
Retry: the wait-time computation ofhandle_retry_on_statusmoves to a private_get_wait_time_on_status, shared byhandle_retry_on_status(unchanged, stilltime.sleep) and a newasync_handle_retry_on_status, which awaitsanyio.sleep. anyio is already installed with thegraphqlextra (through httpx) and works on both asyncio and trio, which the async tests run against. It is imported inside the method so the synchronous clients don't need it.AsyncGraphQL.executeawaitsasync_handle_retry_on_status. The syncGraphQLand REST clients are untouched.
With the reproducer from #3471 , the longest event loop stall goes from 3.16 s to 0.04 s, while execute() still backs off for ~3.1 s before raising GitlabHttpError.
Documentation and testing
Please consider whether this PR needs documentation and tests. This is not required , but highly appreciated:
- Documentation in the matching docs section
- Unit tests and/or functional tests
Unit tests:
test_retry.py:async_handle_retry_on_statusawaits the sleep instead of callingtime.sleep, ignores unknown status codes, and stops atmax_retries.test_graphql.py:test_async_graphql_retries_without_blocking_event_loopretries a 502 without callingtime.sleep(fails onmainfor both asyncio and trio).
fix(graphql): await retry backoff in AsyncGraphQL instead of blocking
5758181
AsyncGraphQL.execute waited between retries with the blocking time.sleep used by the synchronous clients, freezing the event loop for the whole retry sequence (up to ~100 s with the default max_retries, or a full Retry-After on a 429). Add Retry.async_handle_retry_on_status, which shares the wait time computation with handle_retry_on_status but awaits anyio.sleep (asyncio and trio), and use it in AsyncGraphQL.execute. Closes python-gitlab#3471superlevure marked this pull request as ready for review November 19, 2026 09:14 superlevure mentioned this pull request Nov 19, 2026
AsyncGraphQL.execute blocks the event loop with time.sleep while retrying
#3471
Open
codecov
Bot
commented
Nov 19, 2026
Copy link Copy Markdown
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@ ## main #3472 +/- ## ======================================= Coverage 95.78% 95.79% ======================================= Files 100 100 Lines 6172 6184 +12 ======================================= + Hits 5912 5924 +12 Misses 260 260
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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