|
13 | 13 | use reqwest::Client; |
14 | 14 | use std::time::Duration; |
15 | 15 |
|
| 16 | +// ============================================================ |
| 17 | +// Timeout Configuration Constants |
| 18 | +// ============================================================ |
| 19 | +// |
| 20 | +// Timeout Hierarchy Documentation |
| 21 | +// =============================== |
| 22 | +// |
| 23 | +// This module defines the authoritative timeout constants for HTTP operations. |
| 24 | +// Other modules should reference these constants or document deviations. |
| 25 | +// |
| 26 | +// Timeout Categories: |
| 27 | +// - Request timeouts: Total time for a complete request/response cycle |
| 28 | +// - Connection timeouts: Time to establish TCP connection |
| 29 | +// - Read timeouts: Time to receive response data |
| 30 | +// - Pool timeouts: How long idle connections stay in pool |
| 31 | +// |
| 32 | +// Recommended Naming Convention: |
| 33 | +// - Constants: SCREAMING_SNAKE_CASE with Duration type |
| 34 | +// - Config fields: snake_case with _secs suffix for u64 values |
| 35 | +// |
| 36 | +// ============================================================ |
| 37 | + |
16 | 38 | /// User-Agent string for all HTTP requests |
17 | 39 | pub const USER_AGENT: &str = concat!("cortex-cli/", env!("CARGO_PKG_VERSION")); |
18 | 40 |
|
19 | | -/// Default timeout for standard API requests (30 seconds) |
| 41 | +/// Default timeout for standard HTTP requests (30 seconds). |
| 42 | +/// Used for non-streaming API calls, health checks with retries, etc. |
20 | 43 | pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30); |
21 | 44 |
|
22 | | -/// Extended timeout for LLM streaming requests (5 minutes) |
| 45 | +/// Timeout for streaming HTTP requests (5 minutes). |
| 46 | +/// Longer duration to accommodate LLM inference time. |
23 | 47 | pub const STREAMING_TIMEOUT: Duration = Duration::from_secs(300); |
24 | 48 |
|
25 | | -/// Short timeout for health checks (5 seconds) |
| 49 | +/// Timeout for health check requests (5 seconds). |
| 50 | +/// Short timeout since health endpoints should respond quickly. |
26 | 51 | pub const HEALTH_CHECK_TIMEOUT: Duration = Duration::from_secs(5); |
27 | 52 |
|
28 | | -/// Connection pool idle timeout to ensure DNS is re-resolved periodically. |
| 53 | +/// Idle timeout for connection pool (60 seconds). |
| 54 | +/// Connections are closed after being idle for this duration |
| 55 | +/// to allow DNS re-resolution for services behind load balancers. |
29 | 56 | /// This helps with failover scenarios where DNS records change (#2177). |
30 | | -/// Set to 60 seconds to balance between performance and DNS freshness. |
31 | 57 | pub const POOL_IDLE_TIMEOUT: Duration = Duration::from_secs(60); |
32 | 58 |
|
33 | 59 | /// Creates an HTTP client with default configuration (30s timeout). |
|
0 commit comments