Skip to content

fix(tools): reuse reqwest::Client in HttpTool execute() to prevent connection leaks#1545

Open
vivekrajsingh04 wants to merge 3 commits intomofa-org:mainfrom
vivekrajsingh04:fix-httptool-client-reuse
Open

fix(tools): reuse reqwest::Client in HttpTool execute() to prevent connection leaks#1545
vivekrajsingh04 wants to merge 3 commits intomofa-org:mainfrom
vivekrajsingh04:fix-httptool-client-reuse

Conversation

@vivekrajsingh04
Copy link
Copy Markdown
Collaborator

Description

This PR fixes a resource-management issue in HttpTool where reqwest::Client::new() was being called inside the hot path on every single tool invocation.

Because reqwest::Client holds an internal connection pool, async DNS resolver, and TLS session cache, creating a new client per call meant:

  • Every HTTP request started a fresh TLS handshake.
  • Keep-alive connections were never reused.
  • The Tokio executor accumulated background cleanup tasks for dropped connection pools, leading to socket leaks on long-running ReAct agents querying external APIs.

Changes Made

  1. Refactored HttpTool from a unit struct to hold a single client: reqwest::Client.
  2. Added HttpTool::new() and Default implementations.
  3. Updated execute() to use self.client, allowing the underlying connection pool to persist and be safely reused across concurrent executions.
  4. Updated the builtin.rs module documentation example to reflect HttpTool::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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] HttpTool::execute() creates a new reqwest::Client on every invocation — connection pool never reused, sockets leak on long-running agents

1 participant