CancelledError raised on failed requests when on a loop inside asyncio.timeout #2506
Unanswered
marcoffee
asked this question in
Potential Issue
Replies: 2 comments 5 replies
-
|
I've encountered this error as well. @marcoffee, have you determined the cause of the error and found a solution or workaround for it? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I believe this PR fixes the error. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It looks like httpx is not handling
asyncio.Timeoutcancellation when run inside a loop.I was trying to replace
asyncio.wait_forwithasyncio.timeouton async requests with retries and suddenly I started gettingasyncio.CancelledErrors instead of the expectedasyncio.TimeoutErrorHere is a minimal code snippet that causes such error here:
Here, it prints:
Which is unexpected, since the
asyncio.timeoutdecorator should convert theCancelledErrorto aTimeoutError.I tampered a little with the
asyncio.Timeoutclass code and found out that, when it tries to uncancel the running task, it already has7cancelations attempts.Then, I tampered a little more and discovered that those cancellation attempts (two per
cli.getcall) are being triggered insideanyio. Here is a stack trace that I printed every time theTask.cancelwas called.Here is the code that prints such trace:
Maybe this is an issue with some internal
httpxasync call, maybe this is an issue withanyioitself.If it is indeed from
httpx, I would like to open an issue.Beta Was this translation helpful? Give feedback.
All reactions