You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'd like to work on this. The MAT report points at retained clients; the community note about web_fetch/web_search HttpClients is a concrete lead. Plan: audit the tool/extension classes holding OkHttpClient/HttpClient/MCP connections for close()/shutdown paths, add explicit lifecycle release, and (if confirmed) reference the specific retention chain from the MAT dominator tree. Will post findings before the fix since leak attribution from a screenshot alone needs code-level confirmation. PR coming shortly.
@1065609785 To answer your timing question honestly: this is a community-tracked issue — I've claimed it and just finished the code-level confirmation, so the timeline depends on maintainer review of the fix rather than an official schedule. Here's what I found, plus workarounds you can apply today.
Code-level leak chain (confirmed in WebTools.java + HarnessAgent.java:2738-2744):
When web tools are enabled, every HarnessAgent.builder()...build() creates two fresh java.net.http.HttpClient instances (one each for WebFetchTool/WebSearchTool) via the no-arg constructors.
On Java 17–20 those clients cannot be closed (no close() method — added only in Java 21), and each retains its internal selector/executor threads as long as the tool object is reachable from the toolkit.
Repeated agent builds (per-session agent factories, config reloads, multiple HarnessAgent instances) therefore accumulate clients and their threads — consistent with your MAT dominator picture and @chenxb-888's web_fetch/web_search observation. @joman-jiang's GracefulShutdownManager map is plausibly the same retention showing up at a different node.
Interim workarounds:
If you build agents repeatedly, pass one shared, caller-owned client: HarnessAgent.builder().webHttpClient(sharedClient)... — then only one client exists regardless of build count, and its lifecycle is yours to manage.
Or disableWebTools() and register a single custom web tool instance yourself.
Planned fix: reuse a single client across tool instances (and make repeated builds idempotent), plus a shutdown hook where the JDK version supports it. PR to follow after maintainer review of the approach.
Following up on my earlier code-level analysis (the two-fresh-HttpClient-per-build chain): implementing the fix now on the agreed direction — reuse a single shared client across WebFetchTool/WebSearchTool instances when the builder doesn't supply one (idempotent repeated builds), leaving caller-supplied clients untouched. PR coming shortly.
Activity
chenxb-888 commentedon Oct 22, 2026
我也发现了类似问题,通过AI分析,说是web_fetch / web_search这两个新增加的工具持有的HttpClient 没有关闭造成的。
另外,如果有注册mcp给harnessagent,注册的mcp也可能持有HttpClient 导致资源不释放。
joman-jiang commentedon Oct 22, 2026
感觉根因因该是GracefulShutdownManager实例中的ConcurrentHashMap得不到remove,导致内存无法回收吧。
xiaoshuai288 commentedon Oct 22, 2026
应该要调用reActAgent.close();吧,因为每次都是无状态的调用,用完就不需要跟踪请求,直接关闭生命周期
aiyili commentedon Oct 23, 2026
Hi, I'd like to work on this. The MAT report points at retained clients; the community note about web_fetch/web_search HttpClients is a concrete lead. Plan: audit the tool/extension classes holding
OkHttpClient/HttpClient/MCP connections forclose()/shutdown paths, add explicit lifecycle release, and (if confirmed) reference the specific retention chain from the MAT dominator tree. Will post findings before the fix since leak attribution from a screenshot alone needs code-level confirmation. PR coming shortly.1065609785 commentedon Oct 23, 2026
我也遇到了,时间长了,系统无反应,官方什么时间能够修复呢?
aiyili commentedon Oct 23, 2026
@1065609785 To answer your timing question honestly: this is a community-tracked issue — I've claimed it and just finished the code-level confirmation, so the timeline depends on maintainer review of the fix rather than an official schedule. Here's what I found, plus workarounds you can apply today.
Code-level leak chain (confirmed in
WebTools.java+HarnessAgent.java:2738-2744):HarnessAgent.builder()...build()creates two freshjava.net.http.HttpClientinstances (one each forWebFetchTool/WebSearchTool) via the no-arg constructors.close()method — added only in Java 21), and each retains its internal selector/executor threads as long as the tool object is reachable from the toolkit.HarnessAgentinstances) therefore accumulate clients and their threads — consistent with your MAT dominator picture and @chenxb-888's web_fetch/web_search observation. @joman-jiang'sGracefulShutdownManagermap is plausibly the same retention showing up at a different node.Interim workarounds:
HarnessAgent.builder().webHttpClient(sharedClient)...— then only one client exists regardless of build count, and its lifecycle is yours to manage.disableWebTools()and register a single custom web tool instance yourself.Planned fix: reuse a single client across tool instances (and make repeated builds idempotent), plus a shutdown hook where the JDK version supports it. PR to follow after maintainer review of the approach.
aiyili commentedon Oct 28, 2026
Following up on my earlier code-level analysis (the two-fresh-HttpClient-per-build chain): implementing the fix now on the agreed direction — reuse a single shared client across WebFetchTool/WebSearchTool instances when the builder doesn't supply one (idempotent repeated builds), leaving caller-supplied clients untouched. PR coming shortly.
fix(harness): share one default HttpClient across web tools (per-buil…