-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
When using the low-level http.client API, connection timeouts cause the Connection object to enter an improper state which seemingly cannot be reset short of creating a new Connection object.
To reproduce, you'll need an address that produces a timeout. This can be done locally using Python's http.server and whichever firewall solution your OS has (since I'm on Linux, this means nftables):
table ip filter {
chain input {
type filter hook input priority filter;
tcp dport 8000 drop
}
}python -m http.serverFinally, in a Python interpreter, do the following:
from http.client import HTTPConnection
conn = HTTPConnection('127.0.0.1', 8000)
# this request throws TimeoutError
conn.request('HEAD', '/')
# this request throws CannotSendRequest
conn.request('HEAD', '/')
The following do not fix the state of the Connection:
getresponse(): ReturnsAttributeErrorconnect(): Even if the later connection to the address works, theConnectionremains in an invalid state
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-141938/fix-http-client-state-reset #141941
- gh-141938: Fix HTTPConnection being stuck in a dirty state when HTTPResponse.begin() raises exceptions/errors #142047
- gh-141938: document treatment of
OSErrorraised byHTTPConnection.getresponse#142339 - [3.14] gh-141938: document treatment of
OSErrorraised byHTTPConnection.getresponse(GH-142339) #142704 - [3.13] gh-141938: document treatment of
OSErrorraised byHTTPConnection.getresponse(GH-142339) #142705
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error