Repository navigation
fix(graphql): await retry backoff in AsyncGraphQL instead of blocking - #3472
Open
superlevure wants to merge 1 commit into
Open
superlevure wants to merge 1 commit into
superlevure wants to merge 1 commit into
Conversation
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#3471
superlevure
marked this pull request as ready for review
November 19, 2026 09:14
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Changes
Closes #3471.
AsyncGraphQL.executehandled retries throughutils.Retry.handle_retry_on_status, which waits with a blockingtime.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 defaultmax_retries=10andretry_transient_errors=True, or a fullRetry-Afteron a 429 (with the defaultobey_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 raisingGitlabHttpError.Documentation and testing
Please consider whether this PR needs documentation and tests. This is not required, but highly appreciated:
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).