Skip to content

Commit ef5cf51

Browse files
committed
docs(http_client): add comprehensive timeout hierarchy documentation
1 parent c398212 commit ef5cf51

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

src/cortex-common/src/http_client.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,47 @@
1313
use reqwest::Client;
1414
use std::time::Duration;
1515

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+
1638
/// User-Agent string for all HTTP requests
1739
pub const USER_AGENT: &str = concat!("cortex-cli/", env!("CARGO_PKG_VERSION"));
1840

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.
2043
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
2144

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.
2347
pub const STREAMING_TIMEOUT: Duration = Duration::from_secs(300);
2448

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.
2651
pub const HEALTH_CHECK_TIMEOUT: Duration = Duration::from_secs(5);
2752

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.
2956
/// This helps with failover scenarios where DNS records change (#2177).
30-
/// Set to 60 seconds to balance between performance and DNS freshness.
3157
pub const POOL_IDLE_TIMEOUT: Duration = Duration::from_secs(60);
3258

3359
/// Creates an HTTP client with default configuration (30s timeout).

0 commit comments

Comments
 (0)