httpx.ConnectError when performing many async requests #3084
Unanswered
olimcc
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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