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
http.client.HTTPResponse.read(-1) handled incorrectly #112064
Comments
@smason thanks for opening the issue! I'll bring a bit more context from the urllib3/urllib3#3186 discussion here. This together leads to an assumption that the Lines 468 to 494 in 24216d0
|
If no one is working on a PR, I’m happy to take this. |
I was waiting from somebody official to say whether this was a real issue before making a PR... I;ve also noticed that http.client.HTTPResponse doesn't have |
Bug report
Bug description:
http.client.HTTPResponse
doesn't handle negative reads the same as other readers, for example the following code will hang for a significant amount of time:The negative parameter is passed onto the underlying socket which will cause it to try and read to the end-of-stream. For
keep-alive
connections this just blocks until the connection is closed by the server due to inactivity.I think this is a bug with not checking for negative
amt
values in:cpython/Lib/http/client.py
Lines 469 to 471 in 24216d0
Changing the call to
read1
causes the above to display the response promptly as I'd expect. This is due to it correctly checking for negative sizes.cpython/Lib/http/client.py
Lines 654 to 655 in 24216d0
Note that in earlier Python versions, e.g. 3.9, the above fails with
ValueError: negative count
which seems better than timing out, but I think reading to the end of the response makes more sense.CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: