-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Leak Introduced in 1.7.2 #455
Comments
@lidizheng Could you provide guidance on the best way to implement gRPC's |
Okay. This is a bit awkward. The code has been out for 3 years, I guess we need to improve its design. I might get back with a PR or a CL? Which one is preferred? |
Thanks for the quick response! A PR would be preferred. I'm also happy to tweak this myself if you can point me in the right direction. To be completely honest, I have not worked with threading/threadpool, so I was wondering if there was some obvious way to correct this that I was missing. 😅 |
I have a workaround solution that instead of creating a large number of _global_thread_pool = None
class AuthMetadataPlugin(...):
def __init__(self, ...):
global _global_thread_pool
...
if _global_thread_pool is None:
_global_thread_pool = futures.ThreadPoolExecutor() # Let the system default decide number of max_workers
self._pool = _global_thread_pool It solves the spiking number of threads, but not the memory leak issue entirely.
EDIT: Use class static variable is better. class AuthMetadataPlugin(...):
_AUTH_THREAD_POOL = futures.ThreadPoolExecutor()
def __call__(self, context, callback):
...
future = self._AUTH_THREAD_POOL.submit(self._get_authorization_headers, context)
... |
This partially addresses #455, by reducing the number of threads created.
Bug discovered via google-ads-python, original Issue here.
Environment details
google-auth
version: 1.7.2+Steps to reproduce
Not exactly sure since this is exposed in google-ads-python via requests that require user credentials, however the code in this change appears to be the cause. Specifically closing threads in the
__del__
method ofAuthMetadataPlugin
may be causing problems because there are no guarantees around when it's called, and in our case it seems like it may not be called at all.The text was updated successfully, but these errors were encountered: