`AsyncGraphQL.execute` blocks the event loop with `time.sleep` while retrying · Issue #3471 · python-gitlab/python-gitlab
Repository navigation
AsyncGraphQL.execute blocks the event loop with time.sleep while retrying #3471
New issue
New issue
Open
#3472
Open
AsyncGraphQL.execute blocks the event loop with time.sleep while retrying #3471
#3472
Description
@superlevure's profile superlevure opened on Nov 19, 2026Description of the problem, including code/CLI snippet
AsyncGraphQL.execute handles retries through the same utils.Retry helper
as the synchronous clients. Retry.handle_retry_on_status waits with a
blocking time.sleep(wait_time), which in the async client runs on the event
loop's thread. While a request is being retried, the whole event loop
freezes.
Minimal reproduction:
import asyncio
import time
import httpx
import gitlab
def handler(request: httpx.Request) -> httpx.Response:
# Simulate an outage: every request gets a non-JSON 502.
return httpx.Response(502, text="Bad Gateway")
async def heartbeat(gaps: list[float]) -> None:
# Ticks every 10 ms; records how late each tick is.
while True:
start = time.perf_counter()
await asyncio.sleep(0.01)
gaps.append(time.perf_counter() - start)
async def main() -> None:
gaps: list[float] = []
ticker = asyncio.create_task(heartbeat(gaps))
await asyncio.sleep(0.05)
client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
async with gitlab.AsyncGraphQL(
"https://gitlab.example.com",
client=client,
retry_transient_errors=True,
max_retries=5,
) as gq:
start = time.perf_counter()
try:
await gq.execute("query { currentUser { name } }")
except gitlab.exceptions.GitlabHttpError as exc:
print(f"execute() raised after {time.perf_counter() - start:.2f}s: {exc!r}")
# Let the heartbeat record its last (late) tick.
await asyncio.sleep(0.05)
ticker.cancel()
print(f"longest event loop stall: {max(gaps):.2f}s")
asyncio.run(main())
Expected Behavior
The waits between retries yield to the event loop (await asyncio.sleep(...)),
so other tasks keep running while execute backs off.
Actual Behavior
execute() raised after 3.15s: GitlabHttpError("Server error '502 Bad Gateway' for url 'https://gitlab.example.com/api/graphql'...")
longest event loop stall: 3.16s
#3472 should fix the issue.
Specifications
- python-gitlab version: 8.5.0 (the same code is on
main) - gql version: 4.4.0
- httpx version: 0.28.1
- Python version: 3.13.15
- Gitlab server version (or gitlab.com): any (reproduced without a server)