Repository navigation
fix(harness): share one default HttpClient across web tools (per-build leak) - #3833
Merged
Merged
Conversation
每次 HarnessAgent.build() 在未注入 webHttpClient 时,WebFetchTool/ WebSearchTool 各自 new 一个 java.net.http.HttpClient;Java 17-20 的 HttpClient 无 close()(21 才有),客户端及其 selector/executor 线程随工具对象可达性一直存活——按会话工厂/配置重载/多实例反复 构建即持续累积,与 MAT 报告及社区 web_fetch/web_search 观察一致。 - 无参构造改用进程级共享 SHARED_DEFAULT_CLIENT:重复构建幂等, 生命周期与进程一致(单例 client 是 JDK 文档认可的使用方式) - 注入式构造不受影响:caller-owned client 的生命周期仍归调用方 - 并发安全:HttpClient 本身线程安全,共享无串扰 Fixes agentscope-ai#3714
juruoO-o
approved these changes
Nov 12, 2026
juruoO-o
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed shared default HttpClient ownership. Explicitly injected clients retain their existing construction and ownership behavior.
No blocking findings in the reviewed diff. This was a static review of source and tests; local Java/Maven tests were not run.
chickenlj
pushed a commit
that referenced
this pull request
Nov 13, 2026
…d leak) (#3833) Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs. (cherry picked from commit 867c092) Backport-review-patch: d13bdcb9bc7ccb466de52b9a2bf93350e9cee04e Constraint: No AgentScope Service or SDK migration Confidence: high Not-tested: Whole-repository verification pending after lane integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3714
Root cause (code-level confirmation from my earlier analysis on the issue)
Without an injected
webHttpClient, everyHarnessAgent.build()allocated two freshjava.net.http.HttpClientinstances (one per web tool). On Java 17-20 those clients have noclose()(added in 21), so each retains its selector/executor threads as long as the tool objects stay reachable from the toolkit. Repeated builds — per-session agent factories, config reloads, multi-instance deployments — accumulate clients linearly, matching the MAT dominator picture and the web_fetch/web_search observation from @chenxb-888.Fix
The no-arg constructors now share one process-wide
SHARED_DEFAULT_CLIENT: repeated builds become idempotent (zero additional clients), and the shared client's lifecycle intentionally matches the process — a singleton client is the JDK-documented usage pattern andHttpClientis thread-safe. Caller-supplied clients viawebHttpClient(...)/ the explicit constructors are untouched: their lifecycle remains the caller's.Note
@joman-jiang's
GracefulShutdownManagermap hypothesis may be a separate retention node — this PR closes the confirmed per-build client accumulation; if the MAT report still shows growth after this, that map deserves its own investigation.