fix(providers): detect dead/half-open backend connections via TCP keepalive#1272
Draft
Aaronontheweb wants to merge 1 commit into
Draft
fix(providers): detect dead/half-open backend connections via TCP keepalive#1272Aaronontheweb wants to merge 1 commit into
Aaronontheweb wants to merge 1 commit into
Conversation
…palive Switch LLM HttpClient from bare HttpClientHandler to SocketsHttpHandler with aggressive TCP keepalive (idle=10s, interval=5s, probes=3) so that a dead or restarted backend is detected in ~25s instead of hanging for the full 20-minute watchdog budget. The resulting IOException lets the existing FailoverChatClient pre-first-chunk path fail over to the configured fallback provider automatically. Also adds ConnectTimeout (10s), PooledConnectionIdleTimeout (60s), and HTTP/2 PING settings for cloud providers that negotiate h2 over TLS. Closes netclaw-dev#1253
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
HttpClientfrom bareHttpClientHandlertoSocketsHttpHandlerwith aggressive TCP keepalive (idle=10s,interval=5s,probes=3) so a dead or restarted backend is detected in ~25s instead of hanging for the full 20-minute watchdog budgetIOExceptionlets the existingFailoverChatClientpre-first-chunk path fail over to the configured fallback provider automaticallyConnectTimeout(10s),PooledConnectionIdleTimeout(60s), and HTTP/2 PING settings for cloud providers that negotiate h2 over TLSContext
When a self-hosted LLM backend (vLLM, llama.cpp) restarts mid-request, the TCP connection goes half-open — no RST, no data, no exception. The existing
FailoverChatClientonly fails over on exceptions, so the turn hangs for up to 20 minutes (untilProcessingWatchdogcancels) with no failover to the healthy fallback. TCP keepalive probes detect peer death in ~25s, surfacing anIOExceptionthat the existing failover logic already handles.Key insight: TCP keepalive probes peer liveness independently of data flow. A slow-but-alive prefill answers probes (no false kill); a dead/restarted backend doesn't (fast detection → exception → failover).
Verified: vLLM (uvicorn) and llama.cpp (cpp-httplib) are HTTP/1.1 only — HTTP/2 PING frames won't help for self-hosted. TCP keepalive is the primary mechanism.
Closes #1253
Test plan
dotnet build src/Netclaw.Providers/compiles cleanly