Problem description
Each KeyAuth instance starts a daemon thread (token_refresh_task) that loops forever. There's no way to stop it: no public close(), the loop has no exit condition.
We're using the to-be-released pubsub-sdk-python that inherits this in long-running processes (Airflow Trigger) that create more than one KeyAuth over their lifetime (e.g., key rotation), every discarded instance leaks a thread that keeps requesting tokens.
Proposed solution
Add a public, idempotent close()
def close(self) -> None:
"""Stop the background refresh thread and executor. Safe to call more than once."""
self._stop.set()
self.executor.shutdown(wait=False, cancel_futures=True)
atexit.unregister(self.__shutdown)
Modified loop:
def __start_token_refresh_task(self):
def token_refresh_task():
while not self._stop.wait(self.TOKEN_EXPIRY_CHECK_INTERVAL.total_seconds()):
Additional information
Many thanks in advance!
Problem description
Each KeyAuth instance starts a daemon thread (
token_refresh_task) that loops forever. There's no way to stop it: no public close(), the loop has no exit condition.We're using the to-be-released pubsub-sdk-python that inherits this in long-running processes (Airflow Trigger) that create more than one KeyAuth over their lifetime (e.g., key rotation), every discarded instance leaks a thread that keeps requesting tokens.
Proposed solution
Add a public, idempotent close()
Additional information
Many thanks in advance!