Skip to content

fix(foundation): reuse reqwest::Client in HttpTool to prevent connection pool leaks#1575

Open
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
SH20RAJ:fix/1542-httptool-connection-pool
Open

fix(foundation): reuse reqwest::Client in HttpTool to prevent connection pool leaks#1575
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
SH20RAJ:fix/1542-httptool-connection-pool

Conversation

@SH20RAJ
Copy link
Copy Markdown
Contributor

@SH20RAJ SH20RAJ commented Apr 4, 2026

Summary

Fixes #1542 - HttpTool::execute() was creating a new reqwest::Client on every invocation, preventing connection pool reuse and causing resource leaks.

Problem

The reqwest::Client is explicitly documented as a type that must be reused across requests. It holds:

  • Internal connection pool with keep-alive connections
  • Async DNS resolver cache
  • TLS session cache

Creating a new client per call meant:

  • Every HTTP request started a fresh TLS handshake
  • Never reused a keep-alive connection
  • Pool's background tasks leaked until runtime cleanup
  • On long-running agents (ReAct loops), this compounded into socket exhaustion

Solution

Replace the per-invocation Client::new() with a shared static client using once_cell::Lazy. This ensures:

  • Shared connection pool across all invocations
  • Keep-alive connections reused
  • DNS resolver cache hits
  • TLS session cache reuse
  • Reduced latency + lower resource usage

Testing

This fix is compatible with all existing HttpTool tests (no behavior change, only internal resource management). CI should verify no regressions.

GSOC 2026 Contribution

This addresses priority P1 issue #1542, demonstrating expertise with performance-critical optimizations and Rust async patterns.

Cc: @Mustafa11300 @rahulkr182

@SH20RAJ
Copy link
Copy Markdown
Contributor Author

SH20RAJ commented Apr 7, 2026

Friendly ping! This PR reuses reqwest::Client in HttpTool to prevent connection pool leaks. Network resource leak fix. @yangrudan @lijingrs review appreciated 🙏

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