-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix: prevent httpx DeprecationWarning memory leak in AsyncHTTPHandler #16024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Route bytes/str to content= parameter instead of data= to avoid deprecation warning that causes memory leak
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ishaan-jaff
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, can we merge after testing passes
Create _prepare_request_data_and_content() helper to DRY up the logic for routing data/content parameters correctly in httpx requests. This helper prevents httpx DeprecationWarnings (which cause memory leaks) by moving bytes/str from data= to content= parameter while keeping dict/Mapping in data= parameter. Applied the helper consistently across all HTTP methods in both AsyncHTTPHandler and HTTPHandler classes: - post(), put(), patch(), delete() - single_connection_post_request() Related to: b850ed1
cda1105 to
a8e830f
Compare
Replace lowercase tuple[...] with typing.Tuple[...] in http_handler.py to fix 'TypeError: type object is not subscriptable' on Python 3.8
c6bf300 to
a8e3261
Compare
|
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
@ishaan-jaff I’ve fixed all errors related to my changes. The remaining test failures don’t appear to be related, but please let me know if I’m mistaken. |
Title
fix: prevent httpx DeprecationWarning memory leak in AsyncHTTPHandler
Relevant issues
addresses #12685
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🐛 Bug Fix
Changes
Memory Impact
Before
After
Leaky Function
Test Results
[ { "request_number": 1, "memory_allocations": [ { "filename": " File \"/Users/alexsandergomes/.pyenv/versions/3.12.10/lib/python3.12/site-packages/httpx/_content.py\", line 206", "size_diff_bytes": 624, "size_bytes": 624, "count_diff": 7, "count": 7 } ] }, { "request_number": 2, "memory_allocations": [ { "filename": " File \"/Users/alexsandergomes/.pyenv/versions/3.12.10/lib/python3.12/site-packages/httpx/_content.py\", line 206", "size_diff_bytes": 552, "size_bytes": 1088, "count_diff": 6, "count": 12 } ] }, { "request_number": 3, "memory_allocations": [ { "filename": " File \"/Users/alexsandergomes/.pyenv/versions/3.12.10/lib/python3.12/site-packages/httpx/_content.py\", line 206", "size_diff_bytes": 536, "size_bytes": 1536, "count_diff": 6, "count": 17 } ] }, { "request_number": 4, "memory_allocations": [ { "filename": " File \"/Users/alexsandergomes/.pyenv/versions/3.12.10/lib/python3.12/site-packages/httpx/_content.py\", line 206", "size_diff_bytes": 528, "size_bytes": 1976, "count_diff": 6, "count": 22 } ] }, { "request_number": 5, "memory_allocations": [ { "filename": " File \"/Users/alexsandergomes/.pyenv/versions/3.12.10/lib/python3.12/site-packages/httpx/_content.py\", line 206", "size_diff_bytes": 520, "size_bytes": 2408, "count_diff": 6, "count": 27 } ] } ]