You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
authlib.integrations.requests_client.OAuth2Session holds a reference to itself (through self.session) and references each other with Oauth2Auth (through TokenAuth.client). Those two references prevent the unused session objects from being freed until the garbage collector runs a deep cleanup cycle (generation=2).
To Reproduce
Disable garbage collection temporarily to make sure we are the ones who catch it
Set garbage collector's debug level to DEBUG_LEAK
Create and delete an OAuth2Session object
Force a garbage collection run to confirm that the problem exists (the output will list all hard to free objects)
importgcfromauthlib.integrations.requests_clientimportOAuth2Sessionsession=OAuth2Session()
gc.collect() # make sure there is no lingering garbagegc.disable()
gc.set_debug(gc.DEBUG_LEAK)
delsessiongc.collect()
gc.set_debug(0)
Expected behavior
The memory should be freed as soon as the session becomes unused.
Environment:
OS: MacOS and Linux
Python Version: 3.12
Authlib Version: 1.4.0
Additional context
Adding the following finalizers to authlib breaks up the cycles and results in the garbage collector finding no garbage:
Describe the bug
authlib.integrations.requests_client.OAuth2Session
holds a reference to itself (throughself.session
) and references each other withOauth2Auth
(throughTokenAuth.client
). Those two references prevent the unused session objects from being freed until the garbage collector runs a deep cleanup cycle (generation=2
).To Reproduce
DEBUG_LEAK
OAuth2Session
objectExpected behavior
The memory should be freed as soon as the session becomes unused.
Environment:
Additional context
Adding the following finalizers to
authlib
breaks up the cycles and results in the garbage collector finding no garbage:The text was updated successfully, but these errors were encountered: