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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃惤 Fix memory leak in chunked streams handling code (#3631) #3635
Conversation
e9ac7d1
to
d842114
Compare
Codecov Report
@@ Coverage Diff @@
## master #3635 +/- ##
==========================================
- Coverage 97.9% 97.88% -0.03%
==========================================
Files 43 43
Lines 8556 8559 +3
Branches 1376 1377 +1
==========================================
+ Hits 8377 8378 +1
- Misses 74 75 +1
- Partials 105 106 +1
Continue to review full report at Codecov.
|
@mvanderkroon could you please check if this fix helps ? if yes, I will merge and ask for backport. |
@socketpair I can confirm that this fixes it, cheers! |
@asvetlov Please merge. And also backport to 3.5. This is important fix. |
# Prevent memory leak: drop useless chunk splits | ||
while chunk_splits and chunk_splits[0] < self._cursor: | ||
chunk_splits.pop(0) | ||
|
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.
Would it be better to put this code to end_http_chunk_receiving
function? This code is useful only for chunked responses
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.
Well, I will check slightly later
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.
Yes, you are right, but we should trim unused chunk_splits as soon as possible. Suppose many chunk splits in the buffer, including actually last chunk. In your case we will not free that memory until GC collected the stream. In my case we will free splits during content consumption.
@asvetlov please review and merge |
The tests absence worries me. |
I don鈥檛 do python anymore, my python got too rusty. Do not rely on my |
@asvetlov I have added tests... But they check contents of private variable.... |
@socketpair On the other hand, how hard would be to have test against memory leak itself? That one could be useful for all the times. |
Eventually, I tried different methods to check memory usage of Python, and did not find any stable one. So, please approve. I will try to rewrite test in near future through measuring of memory consumption. |
0504111
to
a02426b
Compare
@kxepal I have done it! |
a19a1f0
to
4981e4b
Compare
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.
@socketpair
Sorry for delay, busy times /: LGFM. Memleak test is great! I can reproduce issue with it and the fix.
What do these changes do?
Are there changes in behavior for the user?
Related issue number
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.