Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions agent/auxiliary_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,16 @@ def _evict_cached_client_instance(target: Any) -> bool:
continue
real = getattr(cached, "_real_client", None)
if cached is target or real is target:
# Close the evicted client's transport to release sockets/fds.
# _evict_cached_clients() (by-provider) already does this;
# the instance variant must match. See #10200.
_force_close_async_httpx(cached)
try:
close_fn = getattr(cached, "close", None)
if callable(close_fn):
close_fn()
except Exception:
pass
del _client_cache[key]
evicted = True
return evicted
Expand Down Expand Up @@ -4562,9 +4572,24 @@ def _get_cached_client(
while len(_client_cache) >= _CLIENT_CACHE_MAX_SIZE:
evict_key, evict_entry = next(iter(_client_cache.items()))
_force_close_async_httpx(evict_entry[0])
try:
close_fn = getattr(evict_entry[0], "close", None)
if callable(close_fn):
close_fn()
except Exception:
pass
del _client_cache[evict_key]
_client_cache[cache_key] = (client, default_model, bound_loop)
else:
# Another thread won the race — close the redundant client
# to avoid leaking its httpx transport (sockets/fds).
_force_close_async_httpx(client)
try:
close_fn = getattr(client, "close", None)
if callable(close_fn):
close_fn()
except Exception:
pass
client, default_model, _ = _client_cache[cache_key]
return client, model or default_model

Expand Down
Loading