-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
http.client.HTTPResponse.read(-1) handled incorrectly #112064
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
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 |
…onse.read()` (#128270) The parameter `amt` of `HTTPResponse.read()`, which could be a negative integer, has not been handled before and led to waiting for the connection to close for `keep-alive connections`. Now, this has been fixed, and passing negative values to `HTTPResponse().read()` works the same as passing `None` value.
…TPResponse.read()` (pythonGH-128270) The parameter `amt` of `HTTPResponse.read()`, which could be a negative integer, has not been handled before and led to waiting for the connection to close for `keep-alive connections`. Now, this has been fixed, and passing negative values to `HTTPResponse().read()` works the same as passing `None` value. (cherry picked from commit 4d0d24f) Co-authored-by: Yury Manushkin <manushkin@gmail.com>
…TPResponse.read()` (pythonGH-128270) The parameter `amt` of `HTTPResponse.read()`, which could be a negative integer, has not been handled before and led to waiting for the connection to close for `keep-alive connections`. Now, this has been fixed, and passing negative values to `HTTPResponse().read()` works the same as passing `None` value. (cherry picked from commit 4d0d24f) Co-authored-by: Yury Manushkin <manushkin@gmail.com>
…TTPResponse.read()` (GH-128270) (#129396) gh-112064: Fix incorrect handling of negative read sizes in `HTTPResponse.read()` (GH-128270) The parameter `amt` of `HTTPResponse.read()`, which could be a negative integer, has not been handled before and led to waiting for the connection to close for `keep-alive connections`. Now, this has been fixed, and passing negative values to `HTTPResponse().read()` works the same as passing `None` value. (cherry picked from commit 4d0d24f) Co-authored-by: Yury Manushkin <manushkin@gmail.com>
…TTPResponse.read()` (GH-128270) (#129395) gh-112064: Fix incorrect handling of negative read sizes in `HTTPResponse.read()` (GH-128270) The parameter `amt` of `HTTPResponse.read()`, which could be a negative integer, has not been handled before and led to waiting for the connection to close for `keep-alive connections`. Now, this has been fixed, and passing negative values to `HTTPResponse().read()` works the same as passing `None` value. (cherry picked from commit 4d0d24f) Co-authored-by: Yury Manushkin <manushkin@gmail.com>
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
Linked PRs
HTTPResponse.read()
#128270HTTPResponse.read()
(GH-128270) #129395HTTPResponse.read()
(GH-128270) #129396The text was updated successfully, but these errors were encountered: