Repository navigation
Conversation
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
5 of 6 tasks
…sses a numeric timeout AsyncHTTPHandler.post passed a float per-request timeout straight to build_request, so request_timeout: 600 also became a 600 s connect timeout and replaced the client's 5 s connect timeout. With the aiohttp transport a connect to a stopped upstream's cached IP then hung 40-137 s before the router could fail over. Numeric timeouts now keep connect=min(timeout, HTTP_HANDLER_CONNECT_TIMEOUT_SECONDS), for the request and for the fresh client that retries it after a ConnectError. An explicit httpx.Timeout is passed through unchanged.
…ider tests PydanticAIProviderConfig sends its float timeout through AsyncHTTPHandler.post, so connect is now min(timeout, HTTP_HANDLER_CONNECT_TIMEOUT_SECONDS) while read, write and pool keep the caller's value.
Echo the request timeout in the mock response, and replay through a refusing client so the retry goes through create_client. Signed-off-by: Oliver Yu <[email protected]>
tc3oliver
force-pushed
the
litellm_bounded_connect_timeout
branch
from
November 13, 2026 03:17
e24a7b9 to
7425f58
Compare
Contributor
This branch has not been deployed
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.
TLDR
Problem this solves:
request_timeout: 600also became a 600 s connect timeoutHow it solves it:
AsyncHTTPHandler.postturns a numeric timeout intohttpx.Timeoutmin(timeout, HTTP_HANDLER_CONNECT_TIMEOUT_SECONDS), 5 s todayConnectErrorhttpx.Timeoutfrom the caller is passed through untouchedUser Flow
Before: a user whose request lands on a self-hosted backend that just went down waits over a minute
request_timeout: 600andnum_retries: 2After: the same request fails over after about 6 s
Relevant issues
Refs #47481 (point 2 there, the connect timeout. The stale DNS cache entry and the hidden error are not changed here)
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Self-hosted backends here are fake OpenAI-compatible servers, one docker container each, behind a live proxy on localhost:4100. Repro kit: https://gist.github.com/tc3oliver/0a8f98de57a67a85e3d937107148f4a9. Before is the stock v1.106.0 image. After is the same image with this PR's
http_handler.pydiff applied (patched-http_handler.pyin the kit, main and v1.106.0 differ only in unrelated parts of that file)Config
singleis one deploymentb1withnum_retries: 0andrequest_timeout: 600. Configaffinity-af0is two deploymentsb1/b2withsession_affinity,num_retries: 2,allowed_fails: 0Before (v1.106.0)
One deployment
./run_issue1.sh single single "" "--after 2"(warms b1 twice,docker stop litellm-repro-b1, sends the next requests)500after 72.3 s, 40.0 s and 72.0 s withCannot connect to host litellm-repro-b1:8000 ... [Temporary failure in name resolution], next request500after 3.2 sTwo deployments with session affinity
./run_issue1.sh affinity affinity-af0 "" "--after 3"200from the other deployment after 137.1 s and 72.1 s, later requests 0.02 sAfter (1165261)
One deployment
PATCH=http_handler ./run_issue1.sh single-fixed single "" "--after 2"408 litellm.Timeoutafter 5.8 s, 5.8 s and 5.8 s, next request408after 5.1 sTwo deployments with session affinity
PATCH=http_handler ./run_issue1.sh affinity-fixed affinity-af0 "" "--after 3"200from the other deployment after 6.1 s and 6.2 s, later requests 0.02 sThe 600 s case and the replay test fail on main and pass here.
make lintpassesType
Bug Fix
Caveats (if any)
Medium
HTTP_HANDLER_CONNECT_TIMEOUT_SECONDSis a constant, so proxy users cannot raise ithttpx.TimeoutLow
AsyncHTTPHandler.postchanges,get/put/patch/deletekeep the old behaviorHTTPHandler.posthas the same pattern and is unchangedAsyncHTTPHandler.post, two of its tests pinned connect to the full timeout and now expect the bounded valueallowed_fails_policya stalled connect now counts asTimeoutErrorAllowedFails, notInternalServerErrorAllowedFailsFinal Attestation