From 87d78c2b0f1642627d12a60c834535b56aa06a3b Mon Sep 17 00:00:00 2001 From: teyrebaz33 Date: Wed, 8 Apr 2026 03:52:52 +0300 Subject: [PATCH] fix: close old HTTP client in RegistryTEEConnection.reconnect() Fixes #247 RegistryTEEConnection.reconnect() was replacing self._active without closing the old HTTP client, leaking file descriptors on long-running apps that reconnect frequently. StaticTEEConnection.reconnect() already handled this correctly. Applied the same pattern: save old_client before reconnecting, then aclose() it after the new connection is established. --- src/opengradient/client/tee_connection.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/opengradient/client/tee_connection.py b/src/opengradient/client/tee_connection.py index 2807b88..026e808 100644 --- a/src/opengradient/client/tee_connection.py +++ b/src/opengradient/client/tee_connection.py @@ -153,8 +153,14 @@ def _connect(self) -> ActiveTEE: async def reconnect(self) -> None: """Connect to a new TEE from the registry and rebuild the HTTP client.""" async with self._refresh_lock: + old_client = self._active.http_client try: self._active = self._connect() + except Exception: + logger.debug("Failed to reconnect TEE.", exc_info=True) + return + try: + await old_client.aclose() except Exception: logger.debug("Failed to close previous HTTP client during TEE refresh.", exc_info=True)