googleapis / googleapis/google-cloud-python
google-auth: connection leaks in urllib3 transport and metadata helper during mTLS updates
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1.8k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 122
Description
When mTLS is configured or dynamically updated, the SDK creates and mounts new HTTP adapters/transports but leaves the old ones hanging. While PR #17689 addressed this for the `requests` transport, the leak still exists in two other places:
1. **urllib3 transport (`google/auth/transport/urllib3.py`)**
In `configure_mtls_channel`, `self.http = new_http` replaces the old PoolManager. We need to call `.clear()` on the old `PoolManager` instance before overwriting it so that the active connection pool is cleaned up.
2. **Compute Engine metadata (`google/auth/compute_engine/_metadata.py`)**
If mTLS is enabled, `_metadata.py` instantiates and mounts a new `MdsMtlsAdapter` on the session for every single request. Overwriting the mounted adapter without closing the old one leaks sockets. We should either cache and reuse the adapter or close the old one before mounting.
Contributor guide
Research direction
Read google/auth/transport/urllib3.py and google/auth/compute_engine/_metadata.py, starting with configure_mtls_channel and the per-request MdsMtlsAdapter mounting path. Confirm the old PoolManager is cleaned up and the metadata adapter is reused or closed rather than accumulating sockets, then add or run focused regression tests for both paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- gcp, python
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100