feat: add configurable timeouts and connection pooling for upstream requests#21
Open
bianbiandashen wants to merge 1 commit into
Open
feat: add configurable timeouts and connection pooling for upstream requests#21bianbiandashen wants to merge 1 commit into
bianbiandashen wants to merge 1 commit into
Conversation
…equests Add HTTP client timeout and connection pool configuration to prevent resource exhaustion when upstream LLM APIs are slow or unresponsive. Configuration options (in [upstream] section): - connect_timeout_secs: TCP connection timeout (default: 30s) - request_timeout_secs: Full request/response timeout (default: 300s) - pool_idle_timeout_secs: Idle connection TTL (default: 90s) - pool_max_idle_per_host: Max idle connections per host (default: 32) The default request timeout of 5 minutes accommodates long-running LLM completions while still providing protection against hung connections. Changes: - config.rs: Add timeout fields to UpstreamConfig with sensible defaults - proxy.rs: Add ClientConfig struct and with_config() constructor - lib.rs: Wire up configuration in AppState::from_config() - clawshell.example.toml: Document new configuration options
ADD-SP
reviewed
Feb 15, 2026
| /// Default: 30 seconds. | ||
| #[serde(default = "default_connect_timeout_secs")] | ||
| pub connect_timeout_secs: u64, | ||
|
|
Collaborator
There was a problem hiding this comment.
Would it make sense to use std::time::Duration here?
| /// to accommodate long-running completions. | ||
| /// Default: 300 seconds (5 minutes). | ||
| #[serde(default = "default_request_timeout_secs")] | ||
| pub request_timeout_secs: u64, |
Collaborator
There was a problem hiding this comment.
Would it make sense to use std::time::Duration here?
| /// longer than this duration will be closed. | ||
| /// Default: 90 seconds. | ||
| #[serde(default = "default_pool_idle_timeout_secs")] | ||
| pub pool_idle_timeout_secs: u64, |
Collaborator
There was a problem hiding this comment.
Would it make sense to use std::time::Duration here?
| /// Maximum number of idle connections per host in the connection pool. | ||
| /// Default: 32. | ||
| #[serde(default = "default_pool_max_idle_per_host")] | ||
| pub pool_max_idle_per_host: usize, |
Collaborator
There was a problem hiding this comment.
Would it make sense to use std::time::Duration here?
ADD-SP
force-pushed
the
main
branch
2 times, most recently
from
April 12, 2026 17:00
798e737 to
87955a4
Compare
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.
Summary
Add HTTP client timeout and connection pool configuration to prevent resource exhaustion when upstream LLM APIs are slow or unresponsive.
Problem
The current implementation uses reqwest's default settings with no explicit timeout configuration. If an upstream API (OpenAI/Anthropic) becomes slow or unresponsive:
Solution
Add configurable timeout and connection pool settings in the
[upstream]section:connect_timeout_secsrequest_timeout_secspool_idle_timeout_secspool_max_idle_per_hostThe 5-minute request timeout default accommodates long-running LLM completions while still protecting against hung connections.
Example Configuration
Changes
src/config.rs: Add timeout fields toUpstreamConfigwith default valuessrc/proxy.rs: AddClientConfigstruct andwith_config()constructorsrc/lib.rs: Wire configuration throughAppState::from_config()clawshell.example.toml: Document new configuration optionsTest Plan
ClientConfigdefault valuesProxyClient::with_config()