You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AsyncGraphQL.execute blocks the event loop with time.sleep while retrying #3471
Description 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:
importasyncioimporttimeimporthttpximportgitlabdefhandler(request: httpx.Request) ->httpx.Response:
# Simulate an outage: every request gets a non-JSON 502.returnhttpx.Response(502, text="Bad Gateway")
asyncdefheartbeat(gaps: list[float]) ->None:
# Ticks every 10 ms; records how late each tick is.whileTrue:
start=time.perf_counter()
awaitasyncio.sleep(0.01)
gaps.append(time.perf_counter() -start)
asyncdefmain() ->None:
gaps: list[float] = []
ticker=asyncio.create_task(heartbeat(gaps))
awaitasyncio.sleep(0.05)
client=httpx.AsyncClient(transport=httpx.MockTransport(handler))
asyncwithgitlab.AsyncGraphQL(
"https://gitlab.example.com",
client=client,
retry_transient_errors=True,
max_retries=5,
) asgq:
start=time.perf_counter()
try:
awaitgq.execute("query { currentUser { name } }")
exceptgitlab.exceptions.GitlabHttpErrorasexc:
print(f"execute() raised after {time.perf_counter() -start:.2f}s: {exc!r}")
# Let the heartbeat record its last (late) tick.awaitasyncio.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
Activity