fix(tools): reuse reqwest::Client in HttpTool execute() to prevent connection leaks#1545
Open
vivekrajsingh04 wants to merge 3 commits intomofa-org:mainfrom
Open
fix(tools): reuse reqwest::Client in HttpTool execute() to prevent connection leaks#1545vivekrajsingh04 wants to merge 3 commits intomofa-org:mainfrom
vivekrajsingh04 wants to merge 3 commits intomofa-org:mainfrom
Conversation
…t_tasks semaphore
…nt unbounded memory allocation
HttpTool previously created a new `reqwest::Client` on every invocation of `execute()`, which abandons the underlying connection pool and forces a new TLS handshake per request. This change stores a single shared `reqwest::Client` in the tool struct to ensure socket reuse. Fixes mofa-org#1542
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.
Description
This PR fixes a resource-management issue in
HttpToolwherereqwest::Client::new()was being called inside the hot path on every single tool invocation.Because
reqwest::Clientholds an internal connection pool, async DNS resolver, and TLS session cache, creating a new client per call meant:Changes Made
HttpToolfrom a unit struct to hold a singleclient: reqwest::Client.HttpTool::new()andDefaultimplementations.execute()to useself.client, allowing the underlying connection pool to persist and be safely reused across concurrent executions.builtin.rsmodule documentation example to reflectHttpTool::new().Motivation (GSoC 2026)
I was auditing the scheduling and tool execution paths for my GSoC proposal (Idea 3: Unified Inference Orchestrator) to understand behavior under extended load, and noticed this un-reused pool scaling poorly for high-throughput agents.
Fixes #1542