Skip to content

fix(aiohttp): only set enable_cleanup_closed when required - #21897

Merged
2 commits merged into
BerriAI:litellm_oss_staging_02_23_2026from
SolitudePy:fix/aiohttp-warning
Feb 24, 2026
Merged

fix(aiohttp): only set enable_cleanup_closed when required#21897
2 commits merged into
BerriAI:litellm_oss_staging_02_23_2026from
SolitudePy:fix/aiohttp-warning

Conversation

@SolitudePy

@SolitudePy SolitudePy commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

On modern Python versions (e.g. 3.13.7), aiohttp emits a warning when enable_cleanup_closed is still provided.
This change removes that warning while preserving behavior on Python versions that still require the workaround.

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🐛 Bug Fix

Changes

  • Avoid passing enable_cleanup_closed=True to aiohttp.TCPConnector on Python versions where this workaround is no longer needed.
  • Reuse existing LiteLLM compatibility guard (AIOHTTP_NEEDS_CLEANUP_CLOSED) to conditionally add the connector kwarg.

@vercel

vercel Bot commented Feb 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 22, 2026 7:37pm

Request Review

@SolitudePy

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR conditionally applies enable_cleanup_closed=True to aiohttp.TCPConnector only on Python versions affected by the SSL connection leak bug (Python < 3.12.7 or 3.13.0). Previously, this parameter was unconditionally set, which caused deprecation warnings or errors on newer Python versions where the fix is no longer needed.

  • Removes hardcoded enable_cleanup_closed=True from both AsyncHTTPHandler._create_aiohttp_transport() and _initialize_shared_aiohttp_session() in the proxy
  • Uses the existing AIOHTTP_NEEDS_CLEANUP_CLOSED constant (defined in litellm/constants.py) to conditionally set the parameter
  • Adds 4 unit tests (2 per affected file) verifying the parameter is included/excluded based on the flag
  • All tests use mocks only — no network calls

Confidence Score: 5/5

  • This PR is safe to merge — it's a minimal, well-scoped fix that reuses an existing compatibility constant.
  • The change is small and well-scoped: two production files with a 2-line change each, guarded by an existing well-documented constant. The constant's version logic is already tested in the codebase. Both affected code paths are covered by new mock-only tests. No risk of behavioral regression — the parameter is still set on Python versions that need it.
  • No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/custom_httpx/http_handler.py Conditionally sets enable_cleanup_closed on TCPConnector only when AIOHTTP_NEEDS_CLEANUP_CLOSED is True. Clean, minimal change that correctly reuses the existing constant.
litellm/proxy/proxy_server.py Same conditional enable_cleanup_closed fix applied to the proxy's shared aiohttp session initialization. Correctly imports and uses AIOHTTP_NEEDS_CLEANUP_CLOSED from constants.
tests/test_litellm/llms/custom_httpx/test_aiohttp_cleanup_closed.py New test file with two tests verifying enable_cleanup_closed is set when needed and omitted when not needed for AsyncHTTPHandler._create_aiohttp_transport. Uses mocks correctly.
tests/test_litellm/proxy/test_aiohttp_cleanup_closed.py New test file with two tests verifying the proxy's _initialize_shared_aiohttp_session conditionally passes enable_cleanup_closed. Mock patching is correct because the proxy function uses a local import.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Create aiohttp TCPConnector] --> B{AIOHTTP_NEEDS_CLEANUP_CLOSED?}
    B -->|True: Python < 3.12.7 or 3.13.0| C[Set enable_cleanup_closed=True]
    B -->|False: Python >= 3.12.7 and != 3.13.0| D[Omit enable_cleanup_closed]
    C --> E[Create TCPConnector with kwargs]
    D --> E
    E --> F[Create ClientSession]
Loading

Last reviewed commit: 571d7c6

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ghost
ghost changed the base branch from main to litellm_oss_staging_02_23_2026 February 24, 2026 05:06
@ghost
ghost merged commit d0bcafa into BerriAI:litellm_oss_staging_02_23_2026 Feb 24, 2026
31 checks passed
Sameerlite pushed a commit that referenced this pull request Mar 3, 2026
* fix(aiohttp): only set enable_cleanup_closed when required

* add tests
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…1897)

* fix(aiohttp): only set enable_cleanup_closed when required

* add tests
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant