-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Do we flush the decoder when reaching EOF in partial reads? #2799
Comments
@abebeos Thanks for digging deep into the issue, can't wait to hear your conclusions! Looks like you're on a good path so far. |
Do I understand correctly that code in the main branch as of today flushes the decoder when EOF is reached in partial reads? If so, do you know if we have a test ensuring that a decoder is not left unflushed? |
urllib3/src/urllib3/response.py Lines 937 to 947 in bbba487
It looks like there can be a case when EOF is reached inside the while loop, but flush_decoder is not changed to True .
#3262 does some rearrangements of the code. Maybe it even fixes the issue. However, if so, the fix is lost among other rearrangements, and it is not covered by any new test. |
@illia-v I don't like the approach in that PR, would prefer a simple fix instead of a refactor unless strictly necessary. |
Looks like we don't really need to call flush on a decompress object (at least for the decompressors we have in urllib3). Check here for why that is the case for |
Great sleuthing @zawan-ila! So this means that because we don't support Jython anymore we should be able to remove all logic related to flushing 🚀 |
I started writing a very detailed bug report and then convinced me that it was not real. Sorry, this will be the short version now. Looks at our flush_decoder logic:
urllib3/src/urllib3/response.py
Lines 756 to 794 in 938c0a9
We should only flush when there is no data left. In the streaming case, it would be because we reached EOF, and data is
b''
. Which is done correctly line 776. But then we don't callself._decode
becauseif data
will prevent us from doing it. So we don't flush().This bug was introduced in urllib3 1.11, released in July 2015: 29e144f. Surely in 7 years someone would have noticed if they had missing data.
So surely the flush() call is not actually doing anything, whatever the reason is.
The text was updated successfully, but these errors were encountered: