Buildup of uncollectible garbage when using Client
and AsyncClient
#3276
Unanswered
tsmith023
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
-
httpx version:
0.27.0
Current Behavior:
When using the
Client
andAsyncClient
objects, there seems to be a buildup of uncollectible garbage from their usage. Strangely, the number of uncollectible objects identified by the GC changes depending on whether the return of the client request is assigned to a variable or not.Expected Behavior:
All objects created by the
httpx
library should be garbage collectible so as to avoid memory leakage.Steps To Reproduce:
Sync using response:
leads to:
Sync without using response:
leads to:
Async using response:
leads to:
Async without using response:
leads to:
Here are some forward-ref chain graphs from the second example above (sync without using response):
refs_44
refs_48
refs_76
refs_78
These graphs were made using this code:
Looping through the objects in
gc.garbage
shows that they are all related tohttpx
and its underlying dependencies onhttpcore
&socket/_socket
. I have also found it useful to use the objgraph library to render graphs of the reference dependencies of the uncollectible objects.I may be misunderstanding the action of Python's Garbage Collector as this is the first time that I'm digging into it to understand the problem I'm facing. So if there's some aspect that I may be missing then it would be great to understand that in the context of this issue!
Cheers 😁
Beta Was this translation helpful? Give feedback.
All reactions