Fix #18: Increase pool_idle_timeout from 50s to 600s (10 minutes)#19
Merged
Fix #18: Increase pool_idle_timeout from 50s to 600s (10 minutes)#19
Conversation
The previous 50s pool idle timeout was too aggressive for proxies like MegaLLM that have longer connection timeouts. This caused "poor internet connection" errors after exactly 5 minutes of streaming when connections were closed by the pool while still actively being used. Changes: - Increase default pool_idle_timeout_secs from 50s to 600s (10 minutes) - Update all tests to reflect new default - Add documentation to example config showing how to customize timeouts - Update comments explaining the rationale for the change The new 600s timeout provides: - Stable connections for long-running streaming requests (e.g., extended thinking) - Compatibility with various proxy timeout configurations - Reduced connection overhead from frequent reconnections - Still well below typical load balancer timeouts (30+ minutes) For direct connections to OpenAI/Anthropic (without proxies), users can override this in their config file with http_client.pool_idle_timeout_secs: 50 if desired. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Adds new http_server configuration section to externalize HTTP/TCP settings that were previously hardcoded. This allows users to tune streaming behavior for different network conditions and proxy configurations. New Configuration Options: - tcp_nodelay (bool): Disable Nagle's algorithm for low-latency (default: true) - tcp_keepalive_secs (u64): TCP keepalive interval (default: 60s) - sse_keepalive_enabled (bool): Enable SSE keepalive comments (default: true) - sse_keepalive_interval_secs (u64): SSE keepalive interval (default: 15s) - send_buffer_size (optional): TCP send buffer size in bytes - recv_buffer_size (optional): TCP receive buffer size in bytes Implementation: - Added HttpServerSettings struct with serde defaults - Integrated into ServerConfig with #[serde(default)] - Passed SSE keepalive config to all passthrough routers - Applied to both Anthropic and OpenAI streaming handlers - Updated all three API dialects (OpenAI, Anthropic, Both) - Fixed borrow checker issues by cloning config before async moves Benefits: - Users can adjust SSE keepalive frequency for aggressive proxies (e.g., 10s) - Configurable TCP behavior without code changes - Combined with PR #19's pool_idle_timeout increase, provides full control over both egress (pool) and ingress (SSE) connection behavior - Helps prevent "poor internet connection" errors during long streams Documentation: - Added comprehensive examples to dual-dialect-passthrough.yaml - Explained defaults and when to customize each setting - Server startup logs display configured HTTP server settings Testing: - All 408 unit tests pass - Updated integration tests with new passthrough_router signatures - Clippy passes with no warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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
Fixes #18 - "Poor internet connection" errors after 5 minutes when using proxies like MegaLLM
This PR contains two commits that address connection stability issues:
1. Increase pool_idle_timeout from 50s to 600s (10 minutes)
The previous 50s pool idle timeout was designed to expire connections before upstream servers (OpenAI/Anthropic) close them at 60-120s. However, this was too aggressive for proxies that have longer connection timeouts, causing idle connections to be closed by the pool while actively streaming.
2. Add configurable HTTP server settings for TCP and SSE behavior
Externalizes HTTP/TCP settings that were previously hardcoded, allowing users to tune streaming behavior for different network conditions and proxy configurations.
Problem
With the 50s pool idle timeout and hardcoded SSE keepalive settings:
Solution
Part 1: Pool Idle Timeout (Egress Side)
Increase default
pool_idle_timeout_secsfrom 50s to 600s (10 minutes)Part 2: HTTP Server Configuration (Ingress Side)
Add new
http_serverconfiguration section with:tcp_nodelay(bool): Disable Nagle's algorithm for low-latency (default: true)tcp_keepalive_secs(u64): TCP keepalive interval (default: 60s)sse_keepalive_enabled(bool): Enable SSE keepalive comments (default: true)sse_keepalive_interval_secs(u64): SSE keepalive interval (default: 15s)send_buffer_size(optional): TCP send buffer size in bytesrecv_buffer_size(optional): TCP receive buffer size in bytesBenefits
Changes
Commit 1: Pool Idle Timeout
crates/lunaroute-egress/src/client.rs:HttpClientConfig::default()to setpool_idle_timeout_secs: 600crates/lunaroute-server/src/config.rs:examples/configs/dual-dialect-passthrough.yaml:http_clienttimeoutsCommit 2: HTTP Server Configuration
crates/lunaroute-server/src/config.rs:HttpServerSettingsstruct with serde defaultsServerConfigwith#[serde(default)]crates/lunaroute-server/src/main.rs:crates/lunaroute-ingress/src/{anthropic.rs,openai.rs,multi_dialect.rs}:crates/lunaroute-integration-tests/tests/*.rs:examples/configs/dual-dialect-passthrough.yaml:http_serverconfiguration examplesConfiguration Examples
Default (optimized for streaming with proxies):
For aggressive proxies (e.g., MegaLLM):
For direct API connections (no proxies):
Testing
Compatibility
With Proxies: The new 600s defaults work well with proxies that have longer idle timeouts.
Direct Connections: Users can override settings in their config file if they prefer the more aggressive 50s timeout for direct API connections.
🤖 Generated with Claude Code