litellm - 💡(How to fix) Fix [Bug]:Persitent httpx.ConnectError under heavy load [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23166Fetched 2026-04-08 00:38:11
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Error Message

  1. wait for the connect error
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Under load using an openai model Litellm cloases the client causing persistent httpx.ConnectError. This won't recover unless the container is restarted.

Steps to Reproduce

  1. intantiate an connection using a global http client
  2. bombard an openai model with requests
  3. wait for the connect error

This seems to have something to do with the Client Cache closing all connections on client eviction.

Relevant log output

What part of LiteLLM is this about?

SDK (litellm Python package)

What LiteLLM version are you on ?

v1.181.15

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

The fix involves modifying the HTTP client to handle connection closures and implement a retry mechanism.

Step-by-Step Solution

  • Update the httpx client to use a custom transport with a retry mechanism:

import httpx from tenacity import retry, stop_after_attempt, wait_exponential

@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10)) async def send_request(client, url, params): try: response = await client.get(url, params=params) response.raise_for_status() return response except httpx.ConnectError as e: print(f"Connection error: {e}") raise

*   Implement a custom transport to handle connection closures:
    ```python
import httpx

class CustomTransport(httpx.HTTPTransport):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._closed = False

    def close(self):
        self._closed = True
        super().close()

    def is_closed(self):
        return self._closed
  • Use the custom transport with the httpx client:

client = httpx.Client(transport=CustomTransport())


### Verification
To verify the fix, bombard the OpenAI model with requests and check for persistent `httpx.ConnectError`. If the error no longer occurs, the fix is successful.

### Extra Tips
*   Monitor the application for any other connection-related issues.
*   Consider implementing a circuit breaker pattern to detect and prevent cascading failures.
*   Refer to the `httpx` and `tenacity` documentation for more information on custom transports and retry mechanisms.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]:Persitent httpx.ConnectError under heavy load [1 participants]