xvega commented on code in PR #71349:
URL: https://github.com/apache/airflow/pull/71349#discussion_r3967548797


##########
providers/google/src/airflow/providers/google/cloud/hooks/kubernetes_engine.py:
##########
@@ -514,13 +517,21 @@ def __init__(
 
     @contextlib.asynccontextmanager
     async def get_conn(self) -> AsyncGenerator[async_client.ApiClient, None]:
-        kube_client = None
-        try:
-            kube_client = await self._load_config()
-            yield kube_client
-        finally:
-            if kube_client is not None:
-                await kube_client.close()
+        # Reuse one client per hook: construction parses the CA into an SSL 
context on
+        # the event loop and opens a new connection pool. Released via 
close()/cleanup().
+        if self._cached_kube_client is None:
+            self._cached_kube_client = self._build_client()
+        if self._cached_token is None:
+            self._cached_token = await self.get_token()

Review Comment:
   You’re right. I reproduced this and added a  fix that uses 
credentials.expiry instead of assuming a 3600 seconds lifetime. The existing 
refresh policy now follows the token’s actual remaining lifetime.
   
   Also added regression tests for the 600-second case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to