Race Condition with Cancelled Asyncio Tasks #2821
Unanswered
TheTechromancer
asked this question in
Potential Issue
Replies: 1 comment 5 replies
-
|
Hello, at the moment, httpcore, the networking component of httpx, does not support cancellations; there have been several issues and discussions about this. refs: #2742 This issue has already been resolved in the httpcore master branch, so it should be resolved in httpx with the next httpcore release. |
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.
-
First off, I want to say thanks for making httpx and sorry in advance, as I know this kind of bug can be really annoying to troubleshoot. If it weren't impacting our production systems, I probably wouldn't give it much consideration.
I've run into a race condition which occurs when a task is canceled, but only about 1 out of 1000 times. This has been a difficult one to reproduce in isolation, but I finally was able to do it with the following code:
In essence, this code will create a batch of web requests, get the first successful result, then cancel the rest, rinse and repeat.
On my machine it runs for about ten to twenty iterations, hangs for the specified timeout (5 seconds), then throws an
httpx.PoolTimeouterror and fails to recover.On further inspection it seems that if a task is cancelled at precisely the wrong time, the client is put into a degraded state, unable to issue requests. You can see this in the speed of the iterations, which over the course of this test become more and more erratic until finally the client fails to respond and generates the
PoolTimeout.The bug will not manifest if a new client is instantiated at the beginning of every iteration (e.g. the first line of
return_first_response()).Please let me know if there's anything I can do to help with squashing this.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions