anyio.ClosedResourceError during concurrent HTTP2 GET requests #1719
Replies: 5 comments 6 replies
-
|
On the weekend I received another error: I'll try to downgrade httpcore. |
Beta Was this translation helpful? Give feedback.
-
|
I'm suffering the same scenario. There's any update on this discussion? |
Beta Was this translation helpful? Give feedback.
-
|
I'm encountering same issue using both threads and asyncio (KeyError: (<ConnectionState.CLOSED: 3>, <ConnectionInputs.SEND_HEADERS: 0>) etc for threads and same as @DXist for asyncio) but only when reusing same client instance, if creating new client instance per requests everything works fine. I'm making hundreds requests per second to same set of hosts (1-2 hosts per instance), max 300 connections + max 100 keepalive in both. UPD: Tested some lower versions, it's present at least down to httpcore 0.13.3 so it seems it runs deeper than that Full text of error for sync version, the request is made like
Full error for asyncio version, the response is awaited like
We don't close httpx.Client\AsyncClient instances ourselves whatsoever (nor any other pool\session-like objects we use from urllib3, aiohttp etc) until app is killing self (the only exception is when creating new httpx.Client\request.Session instance in "no pooling" variant, we let GC handle that because we have increased connections limit anyway), so if there is nothing wrong with our code (most likely not because aiohttp and urllib3 dont share same behavior when reusing client\pool) it seems like this error stems from httpcore or h2 most likely because httpx built on top of them, AFAIK. I've encountered this error mostly after some requests have failed (e.g. couldnt connect to proxy) or some requests timed out using same reused httpx.Client |
Beta Was this translation helpful? Give feedback.
-
|
Seems like recent httpcore release 0.14.* resolved this issue for us so most likely this is resolved now, thanks to @tomchristie 's rewrite of httpcore. @DXist have you tried the most recent versions of httpx and httpcore and if so has the problem disappeared for you too? |
Beta Was this translation helpful? Give feedback.
-
|
Today, I got a similar effect with httpx[http2] 0.23.3 and httpx-sse 0.1.0. I use a shared global httpx.AsyncClient created in a FastAPI lifespan method and call only Maybe it is related to encode/httpcore#87 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I use async httpx client to issue multiple HTTP2 GET requests (10 workers per host) and sometimes get
anyio.ClosedResourceErrorexception (see traceback below).The service I connect to fails often and returns 500 errors. Some requests just get timeouts.
Default timeout on the client is 10, read timeout is 60. Sometimes I see log messages about happened ReadTimeout before the exception happens. I connect to a service behind Nginx reverse proxy and 60 seconds is a default proxy connect/read timeout for Nginx.
httpx version is 0.18.2, httpcore version is 0.13.6. I found a commit in httpcore related to connection close and read timeouts. I didn't get this error before this change but haven't tested the previous version extensively.
Beta Was this translation helpful? Give feedback.
All reactions