Skip to content

fix(http): configure explicit timeouts and improve connection pooling#5737

Open
leseb wants to merge 2 commits intoogx-ai:mainfrom
leseb:fix-http-client-timeout-and-improve-connection-poo
Open

fix(http): configure explicit timeouts and improve connection pooling#5737
leseb wants to merge 2 commits intoogx-ai:mainfrom
leseb:fix-http-client-timeout-and-improve-connection-poo

Conversation

@leseb
Copy link
Copy Markdown
Collaborator

@leseb leseb commented May 6, 2026

Summary

  • Configure explicit httpx.Timeout(total, connect=...) on every httpx.AsyncClient in the codebase, replacing bare defaults or per-request timeout= kwargs. Total timeout of 30s for tool runtimes / content fetch and 10s for auth endpoints; connect timeout set shorter (10s / 5s respectively) to fail fast on unreachable hosts.
  • Introduce BaseToolRuntimeConfig with user-tunable timeout and connect_timeout fields so operators can adjust HTTP timeouts per tool runtime provider (Bing Search, Brave Search, Tavily Search, Wolfram Alpha) via config YAML.
  • Reuse a persistent httpx.AsyncClient in CustomAuthProvider instead of creating a new client per validate_token call, reducing TCP/TLS setup overhead.
  • Add validate_url_not_private() SSRF guard to file_search and prompt_adapter image localization paths, blocking requests to loopback, link-local, and RFC 1918 addresses (including IPv4-mapped IPv6).

Test plan

  • tests/unit/core/test_client_timeout.py — verifies the API client factory no longer puts timeout inside per-request params (it is set on the AsyncClient constructor instead).
  • tests/unit/server/test_auth_http_client.py — verifies CustomAuthProvider creates its client eagerly with the correct connect/read/write/pool timeouts, reuses it, and closes it properly.
  • tests/unit/server/test_auth_oauth2_introspection.py — updated assertions to match the new httpx.Timeout object passed to AsyncClient and confirms timeout is no longer passed per-request.
  • tests/unit/providers/utils/test_url_validation.py — comprehensive coverage for validate_url_not_private: loopback, RFC 1918, link-local, IPv6 loopback/ULA/link-local, IPv4-mapped IPv6, unresolvable hostnames, mixed DNS results, and public IP allowlisting.
  • Run full unit test suite: uv run pytest tests/unit/ -x --tb=short
  • Run pre-commit checks: uv run pre-commit run --all-files

🤖 Generated with Claude Code

… HTTP clients

Replace default httpx timeouts with explicit Timeout(total, connect=connect)
across the codebase to fail fast on unreachable hosts while still allowing
slow upstream responses. Introduce BaseToolRuntimeConfig with configurable
timeout/connect_timeout fields so tool runtime providers (Bing, Brave,
Tavily, Wolfram Alpha) expose these as user-tunable config. Reuse a
persistent httpx.AsyncClient in CustomAuthProvider instead of creating one
per request. Add SSRF protection via validate_url_not_private for URLs
fetched in file_search and prompt_adapter image localization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
pytest is configured with async-mode=auto, so the explicit decorator
is unnecessary and blocked by the pre-commit hook.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
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.

1 participant