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
{{ message }}
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
AuthorizedSession's _auth_request sub-session is never cleaned #658
As you may be aware, requests.Session() objects should be .close()d (or used as context managers) so the underlying connection pool gets shut down.
The above-linked code path creates a separate requests.Session() and a google.auth.transport.requests.Request object using it when no explicit Request object is passed in (and this seems to be the default for a trivial use of e.g. google-cloud-storage).
When that happens, the secondary session (only used for refreshing credentials) is never cleaned up even if the owning session might be.
message to be logged since the sub-session's HTTP adapter is initialized with max_retries=3; this is indeed what the requests manual says, but changing that to max_retries=Retry(3, redirect=True) (where Retry comes from urllib3) would fix that.
Remedy
I think AuthorizedSession should remember whether it initialized this subsession, and if it did, have it clean it up on close(); something like
might do since close() is already automatically called by requests.Session.__exit__(), so careful users of AuthorizedSession will benefit from this immediately.
I'm willing to formalize this into a PR if the plan sounds good.
Workaround
I'm currently making sure to close those pools with a hack like this.
Activity
parthea commentedon Jun 24, 2021
@busunkim96 , This is possibly solved by googleapis/python-cloud-core#100 . WDYT?
parthea commentedon Jun 28, 2021
@tseaver Please can you take a look?
fix: avoid leaking sub-session created for '_auth_request'
fix: avoid leaking sub-session created for '_auth_request' (#789)