[Bug]: Closing one client from a ClientFactory closes the shared httpx client for every other client
維護者通常 2 天內回覆
評估
這個 Issue 還沒有評估資料。
描述
What happened?
Since #947, ClientFactory creates a single httpx.AsyncClient in __init__ (src/a2a/client/client_factory.py) and passes it to every transport it creates, and to the card resolver in create_from_url:
httpx_client = config.httpx_client or httpx.AsyncClient()
...
self._httpx_client = httpx_client
Each HTTP transport closes that client in close() (JsonRpcTransport.close, RestTransport.close and the v0.3 compat transports):
async def close(self) -> None:
"""Closes the httpx client."""
await self.httpx_client.aclose()
So closing one client, explicitly or by leaving async with client:, closes the HTTP client shared by every other client from the same factory, and by the factory itself. Before #947 each transport got its own httpx.AsyncClient() unless one was passed in ClientConfig, so this did not happen.
Reproduction:
factory = ClientFactory()
client_a = factory.create(card_a)
client_b = factory.create(card_b)
async with client_a:
...
await client_b.get_task(GetTaskRequest(id='task-1'))
# RuntimeError: Cannot send a request, as the client has been closed.
await factory.create_from_url('https://agent-c.example')
# RuntimeError: Cannot send a request, as the client has been closed.
The error is a raw RuntimeError from httpx, not an A2AClientError, so it is also not caught by code handling SDK errors. The create_client docstring suggests using ClientFactory directly "for reusing a factory across multiple agents", which is the case that breaks.
Expected: closing a client releases only its own resources. Other clients from the same factory, and the factory itself, keep working.
I see two possible directions, depending on whether sharing the connection pool across clients was a goal of #947:
Option A: one HTTP client per created client (as before #947). When ClientConfig.httpx_client is not set, each create() builds its own httpx.AsyncClient (with the same default A2A-Version header), and create_from_url resolves the card with its own short-lived client. Small change, no new API, same behavior as before #947.
Option B: the factory owns the shared client. Transports stop closing an HTTP client they did not create, and ClientFactory gets close() and async with support to release the shared client. Keeps a single connection pool, but adds API surface and makes the factory responsible for its lifetime.
In both cases, a client passed through ClientConfig.httpx_client would be left to the caller to close. Today the SDK closes it too, which was already the case before #947, so I'm happy to keep that out of scope if you prefer.
Happy to open a PR with either option, or with a different approach if you have one in mind. Just let me know which direction you prefer.
Code of Conduct
- I agree to follow this project's Code of Conduct
- 主要語言
- Python
- 星號
- 2.2k
- 分支
- 532
- 平均合併
- 3 天 6 小時
- 30 天內合併 PR
- 42
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
a2aproject/a2a-python 的其他 Issue
-
[Bug]: `A2A-Version` validation ignores minor versions and the query parameter可能已有人在做 @rohityan 於 72 天前認領。 未關閉component: server status:awaiting response status:stale
難度 2/5 1-3 小時 新手友好度 75/100
a2aproject/a2a-python#1204 · 4 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
-
[Bug]: REST task/request id sanitization可能已有人在做 @Linux2010 於 130 天前認領。 未關閉maintainers-only
難度 2/5 1-3 小時 新手友好度 65/100
a2aproject/a2a-python#805 · 1 則留言 ·
維護者通常 2 天內回覆
-
[Bug]: v0.3 REST client raises NotImplementedError for list_task_push_notification_configs可能已有人在做 @RaphaelFakhri 於 1 天前認領。 未關閉component: client status:awaiting response
a2aproject/a2a-python#1423 · 1 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
-
[Bug]: ActiveTask.start() leaves the event queue dispatchers pending when setup fails可能已有人在做 @cchinchilla-dev 於 1 天前認領。 未關閉component: server status:awaiting response
a2aproject/a2a-python#1421 · 1 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
-
Compat REST client drops security from the v0.3 extended agent card可能已有人在做 @ConnorMoss02 於 1 天前認領。 未關閉component: client status:awaiting response
a2aproject/a2a-python#1418 · 1 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
查看 a2aproject/a2a-python 的全部 Issue
相似的 Issue
-
follow-up needs-triage S3: minor
難度 2/5 1-3 小時 新手友好度 72/100
manaflow-ai/cmux#36856 · 1 則留言 ·
維護者通常 1 天內回覆
-
documentation good first issue help wanted
難度 1/5 1-3 小時 新手友好度 90/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 73/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
-
Shell framework build fails at "copy the shader libraries": the iOS shader libraries are now one file b-<chain>.img可能已有人在做 @xiaofeng-han 今天認領。 未關閉build ios
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆