httpx.ConnectError when performing many async requests #3084
Replies: 5 comments
-
I'm having the same problem, did you ever figure it out? |
Beta Was this translation helpful? Give feedback.
-
I am facing this exact same problem right now with multiple |
Beta Was this translation helpful? Give feedback.
-
Has anyone figured out a fix? |
Beta Was this translation helpful? Give feedback.
-
it's kind of crazy to see something like this in one of the most commonly used http request libraries across the globe... |
Beta Was this translation helpful? Give feedback.
-
Looks related to python/cpython#112169 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We often experience
httpx.ConnectError
s when making API calls with the httpx async client, we can reproduce this by passing many (~1000s) of async requests to the client. Oddly it manifests as anodename nor servname provided
exception. Based on some experimentation, it looks like this might be related tomax_keepalive_connections
andkeepalive_expiry
. To rule out other culprits (load balancer, service itself) I'm running an equivalent test with aiohttp, which has no problem completing the same volume of requests. It's a different exception, but it seems comparable to experiences noted in #1171. Is there a recommended configuration or approach I should use here?I have found that passing 10,000 GETs to a pretty bare-bones AsyncClient, to a variety of hosts, from my local machine achieves it every time. I've shared a full testing script below. I'am typically able to achieve a successful outcome by tweaking
httpx.Limits
to some ~extreme settings:In the case of error, the (abridged) exception:
Full stack trace
Testing script
Versions & configuration
Hardare: Mac / M1 Pro
Service target: uvicorn/fastapi, behind an AWS ALB (load balancer)
Python: 3.11.3
Pip freeze:
Beta Was this translation helpful? Give feedback.
All reactions