Skip to content

fix(graphql): await retry backoff in AsyncGraphQL instead of blocking - #3472

Open
superlevure wants to merge 1 commit into
python-gitlab:mainfrom
superlevure:fix/async-graphql-blocking-retry
Open

superlevure wants to merge 1 commit into
python-gitlab:mainfrom
superlevure:fix/async-graphql-blocking-retry

Conversation

@superlevure

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 of handle_retry_on_status moves to a private _get_wait_time_on_status, shared by handle_retry_on_status (unchanged, still time.sleep) and a new async_handle_retry_on_status, which awaits anyio.sleep. anyio is already installed with the graphql extra (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.execute awaits async_handle_retry_on_status. The sync GraphQL and 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:

Unit tests:

  • test_retry.py: async_handle_retry_on_status awaits the sleep instead of calling time.sleep, ignores unknown status codes, and stops at max_retries.
  • test_graphql.py: test_async_graphql_retries_without_blocking_event_loop retries a 502 without calling time.sleep (fails on main for both asyncio and trio).

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
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.79%. Comparing base (a4053bf) to head (5758181).

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           
Flag Coverage Δ
api_func_v4 83.68% <57.89%> (-0.23%) ⬇️
cli_func_v4 78.71% <36.84%> (-0.08%) ⬇️
unit 90.34% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
gitlab/client.py 98.55% <100.00%> (ø)
gitlab/utils.py 98.70% <100.00%> (+0.10%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncGraphQL.execute blocks the event loop with time.sleep while retrying

1 participant